1.4
> x <- 11
> x
[1] 11
> x1 <- c(1,3,5,7,9)
> x1
[1] 1 3 5 7 9
> gender <- c("male", "female")
> gender
[1] "male" "female"
> 2:7
[1] 2 3 4 5 6 7
> seq(from=1, to=7, by=1)
[1] 1 2 3 4 5 6 7
> seq(from=1, to=7, by=1/3)
[1] 1.000000 1.333333 1.666667 2.000000 2.333333 2.666667 3.000000 3.333333 3.666667 4.000000 4.333333 4.666667
[13] 5.000000 5.333333 5.666667 6.000000 6.333333 6.666667 7.000000
> seq(from=1, to=7, by=0.25)
[1] 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 5.25 5.50 5.75 6.00 6.25 6.50
[24] 6.75 7.00
> rep(1, times=10)
[1] 1 1 1 1 1 1 1 1 1 1
> rep("marin", times=5)
[1] "marin" "marin" "marin" "marin" "marin"
> rep(1:3, times=5)
[1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
> rep(seq(from=2, to=5, by=0.75), times=5)
[1] 2.00 2.75 3.50 4.25 5.00 2.00 2.75 3.50 4.25 5.00 2.00 2.75 3.50 4.25 5.00 2.00 2.75 3.50 4.25 5.00 2.00 2.75 3.50
[24] 4.25 5.00
> rep(c("m", "f"), times=5)
[1] "m" "f" "m" "f" "m" "f" "m" "f" "m" "f"
> x <- 1:5
> y <- c(1,3,5,7,9)
> y
[1] 1 3 5 7 9
> x
[1] 1 2 3 4 5
> x + 10
[1] 11 12 13 14 15
> x - 10
[1] -9 -8 -7 -6 -5
> x * 10
[1] 10 20 30 40 50
> x/2
[1] 0.5 1.0 1.5 2.0 2.5
> x + y
[1] 2 5 8 11 14
> x-y
[1] 0 -1 -2 -3 -4
> x*y
[1] 1 6 15 28 45
> x/y
[1] 1.0000000 0.6666667 0.6000000 0.5714286 0.5555556
>
> x
[1] 1 2 3 4 5
> y
[1] 1 3 5 7 9
> y[3]
[1] 5
> y[-3]
[1] 1 3 7 9
> y[1:3]
[1] 1 3 5
> y[c(1,5)]
[1] 1 9
> y[-c(1,5)]
[1] 3 5 7
> y[y<6]
[1] 1 3 5
> y[x<6]
[1] 1 3 5 7 9
> matrix(1:9, nrow=3, byrow=TRUE)
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
> mat <- matrix(1:9, nrow=3, byrow=FALSE)
> mat
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> mat <- matrix(1:9, nrow=3, byrow=TRUE)
> mat
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
> mat[1, 2]
[1] 2
> mat[c(1,3), 2]
[1] 2 8
> mat[2]
[1] 4
> mat[2,]
[1] 4 5 6
> mat[,1]
[1] 1 4 7
> mat*10
[,1] [,2] [,3]
[1,] 10 20 30
[2,] 40 50 60
[3,] 70 80 90