






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







x <- c(10.4, 5,6, 3.1, 6.4, 21.7) # set up vector x x [1] 10.4 5.0 6.0 3.1 6.4 21.
assign("x",c(10.4, 5,6, 3.1, 6.4, 21.7))
x <- c(0,5,9,12,35) length(x) [1] 5 sum(x) [1] 61 mean(x) [1] 12. sd(x) [1] 13.
paste("Georgia","Bulldog") [1] "Georgia Bulldog" x= paste("the value of x is", x) [1] "the value of x is 2" labs <- paste(c("X","Y"), 1:10, sep="") labs [1] "X1" "Y2" "X3" "Y4" "X5" "Y6" "X7" "Y8" "X9" "Y10"
as.character(y) [1] "0" "1" as.numeric(z) [1] NA NA Warning message: NAs introduced by coercion x = c(TRUE,FALSE) y = c(0,1) z = c(’a’,’1’) as.numeric(x) [1] 1 0 as.character(x) [1] "TRUE" "FALSE" as.logical(y) [1] FALSE TRUE as.character(y) [1] "0" "1" as.logical(z) [1] NA NA as.numeric(z) [1] NA 1 Warning message: NAs introduced by coercion
x <- c(1, 1, 1, 1, 1, 2, 2, 2, 2, 9, 9, 9, 9) factor(x) # notice levels are printed. [1] 1 1 1 1 1 2 2 2 2 9 9 9 9 Levels: 1 2 9
x <- c("like", "dislike", "hate", "like", "don’t know", "like", "dislike")
factor(x, levels = c("hate", "dislike", "like", "don’t know"), ordered = TRUE) [1] like dislike hate like don’t know like dislike Levels: hate < dislike < like < don’t know
factor(x,order=TRUE) [1] like dislike hate like don’t know like dislike Levels: dislike < don’t know < hate < like
factor(x, levels = c("hate", "dislike", "like"), ordered = TRUE) [1] like dislike hate like
like dislike Levels: hate < dislike < like
x <- c(1:3,NA,4) x [1] 1 2 3 NA 4 l = c(T,T,T,F,T) y <- x[l]
fruit <- c(5, 10, 1, 20) names(fruit) <- c("orange", "banana", "apple", "peach") fruit orange banana apple peach 5 10 1 20 fruit[c("apple","orange")] apple orange 1 5