wants <- c("car")
has <- wants %in% rownames(installed.packages())
if(any(!has)) install.packages(wants[!has])
Lower types can be uniquely converted to higher types.
[1] 1 0 0 1
[1] 1+0i 0+0i 0+0i 1+0i
[1] "TRUE" "FALSE" "FALSE" "TRUE"
Higher types cannot be uniquely converted to lower types.
[1] TRUE FALSE TRUE TRUE
Warning: imaginary parts discarded in coercion
[1] 3 3 0 0
Warning: NAs introduced by coercion
[1] 21.000 3.141 NA
[1] 20 19 18 17 16 15 14 13 12 11 10
[1] 1 6 7 10 10 12 12 16 19 19
[1] 8 10 6 2 4 1 9 5 7 3
[1] 19 19 16 12 12 10 10 7 6 1
[1] "10" "4" "A" "A" "D" "D" "E" "E" "E" "F"
set.seed(123)
myColors <- c("red", "green", "blue", "yellow", "black")
(randCols <- sample(myColors, length(myColors), replace=FALSE))
[1] "blue" "green" "black" "yellow" "red"
[1] 1 1 1 1 2 2 2 3 3 3 3 3
[1] 2 3 2 1 3 3 1 1 1 2 3 3
x <- c(18, 11, 15, 20, 19, 10, 14, 13, 10, 10)
N <- length(x)
P <- 3
(sample(1:N, N, replace=FALSE) %% P) + 1
[1] 1 2 2 3 1 3 1 2 3 2
[1] "red" "red" "green" "green" "green"
[1] "red" "red" "blue" "blue" "blue"
[1] "red" "green" "blue"
character(0)
[1] 1.8 2.0 3.0 2.4 2.3 2.1
[1] 14.0 15.0 20.0 17.0 16.5 15.5
[1] -6 8 -10 12
[1] 1e-01 6e-02 3e-03 8e-04
vec1 <- c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24)
vec2 <- c(2, 4, 6, 8, 10)
c(length(age), length(vec1), length(vec2))
[1] 6 12 5
[1] 36 80 180 192 230 252 252 320 540 480 506 504
Warning in vec2 * age: longer object length is not a multiple of shorter object
length
[1] 36 80 180 192 230 42
[1] -1.1166106 -0.6380632 1.7546739 0.3190316 0.0797579 -0.3987895
[,1]
[1,] -1.1166106
[2,] -0.6380632
[3,] 1.7546739
[4,] 0.3190316
[5,] 0.0797579
[6,] -0.3987895
attr(,"scaled:center")
[1] 22.66667
attr(,"scaled:scale")
[1] 4.179314
[1] -1.1166106 -0.6380632 1.7546739 0.3190316 0.0797579 -0.3987895
[1] 83.25084 90.42905 126.32011 104.78547 101.19637 94.01816
[1] 100
[1] 15
[1] 3.5 1.0 2.0 3.5
height <- c(1.78, 1.91, 1.89, 1.83, 1.64)
weight <- c(65, 89, 91, 75, 73)
(bmi <- weight / (height^2))
[1] 20.51509 24.39626 25.47521 22.39541 27.14158
quest1 <- c(FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE)
quest2 <- c(TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE)
quest3 <- c(TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE)
(sumVar <- quest1 + quest2 + quest3)
[1] 2 1 1 2 1 3 1 1
R markdown - markdown - R code - all posts