NutriNews Issue 7 2017 NutriNews Issue 7 2017 | Page 29

> x <- 0:6 > class(x) [1] "integer" > as.numeric(x) [1] 0 1 2 3 4 5 6 > as.logical(x) [1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE > as.character(x) [1] "0" "1" "2" "3" "4" "5" "6" > ## Create a vector with NAs in it > x <- c(1, 2, NA, 10, 3) > ## Return a logical vector indicating which elements are NA > is.na(x) [1] FALSE FALSE TRUE FALSE FALSE > ## Return a logical vector indicating which elements are NaN > is.nan(x) [1] FALSE FALSE FALSE FALSE FALSE > ## Now create a vector with both NA and NaN values > x <- c(1, 2, NaN, NA, 4) > is.na(x) [1] FALSE FALSE TRUE TRUE FALSE > is.nan(x) [1] FALSE FALSE TRUE FALSE FALSE The Rise of R and Open Science By: Luke Johnston > ## Create a data frame > y <- data.frame(a = 1, b = "a") > ## Print 'dput' output to console > dput(y) structure(list(a = 1, b = structure(1L, .Label = "a", class = "factor")), .Names\ = c("a", "b"), row.names = c(NA, -1L), class = "data.frame") > a <- data.frame(x = rnorm(100), y = runif(100)) > b <- c(3, 4.4, 1 / 3) > > ## Save 'a' and 'b' to a file > save(a, b, file = "mydata.rda") > str(file) function (description = "", open = "", blocking = TRUE, encoding = getOption("en\ coding"), raw = FALSE) Issue 3 | Nutrition of Everything | 23