numb_vect <- c(1:4, 4:10, 9:14, 1:3) numb_vect print(length(numb_vect))
char_vect <- as.character(numb_vect) char_vect
num_factr <- as.factor(numb_vect) num_factr
nlevels(num_factr) length(unique(num_factr))
named_list <- list(rank = 10, Iconic_HH_group = c(“Mos Def”, “Tablib Kwali”, “BlackStar”)) named_list$Iconic_HH_group[12]
#Cost of living in various US States
US_State <- as.character(c(“TX”, “NE”, “OH”, “KS”, “KY”, “OK”, “TN”, “NM”, “AZ”, “MO”)) Utilities_Cost <- c(“$120”, “$130”, “$140”, “$150”, “$160”, “$170”, “$180”, “$190”, “$200”, “$200”) Internet_Cost <- c(“$50”, “$55”, “$58”, “$52”, “$69”, “$57”, “$52”, “$54”, “$56”, “$88”) Gas_per_gal <- c(“$1.25”, “$1.35”, “$2.50”, “$5.50”, “$200”, “$3.25”, “$0.50”, “$0.77”, “$9.0”, "\(8000") df <- data.frame(US_State, Utilities_Cost, Internet_Cost, Gas_per_gal) df\)US_State <- as.character(df$US_State) str(df)
dfnew <- data.frame(US_State = ‘MI’, Utilities_Cost = ‘$180’, Internet_Cost = ‘$60’, Gas_per_gal = ’\(1.33') str(dfnew) dfnew\)Gas_per_gal <- as.character(dfnew\(Gas_per_gal) dfnew\)US_State <- as.character(dfnew\(US_State) str(dfnew) dfnew\)US_State str(dfnew) df <- rbind(df, dfnew) df str(df)
tmp <- read.csv(file = “temperatures.csv”) tmp
i <- 1500 r <- 0.0324 cmpt <- 12 yrs <- 6
{ i <- i + (i * r / cmpt) } print(i) # prints 1821.396 sprintf(“%.2f”, i) #formats as 1821.40
i <- i * ( 1 + (r/cmpt)) ^ (cmpt * yrs) print (i)
t <- 1:20 sum(t[seq(0, length(t), 3)])
x <- 2 k <- 0 for (i in 1:10) { k <- k + x^i
}
print (k)
y <- 2 j <- 0 i <- 1 while (i <= 10) { j <- j + y^i i <- i+1
} print(j)
w <- 2 print(sum(x^(1:10)))