Intermediate R
Filip Schouwenaars
DataCamp Instructor
sapply()
, vapply()
, lapply()
sort()
print()
identical()
...v1 <- c(1.1, -7.1, 5.4, -2.7)
v2 <- c(-3.6, 4.1, 5.8, -8.0)
mean(c(sum(round(abs(v1))), sum(round(abs(v2)))))
v1 <- c(1.1, -7.1, 5.4, -2.7)
v2 <- c(-3.6, 4.1, 5.8, -8.0)
mean(c(sum(round(abs(v1))), sum(round(abs(v2)))))
abs(c(1.1, -7.1, 5.4, -2.7))
1.1 7.1 5.4 2.7
abs(c(-3.6, 4.1, 5.8, -8.0))
3.6 4.1 5.8 8.0
mean(c(sum(round(c(1.1, 7.1, 5.4, 2.7))),
sum(round(c(3.6, 4.1, 5.8, 8.0)))))
v1 <- c(1.1, -7.1, 5.4, -2.7)
v2 <- c(-3.6, 4.1, 5.8, -8.0)
mean(c(sum(round(abs(v1))), sum(round(abs(v2)))))
mean(c(sum(round(c(1.1, 7.1, 5.4, 2.7))),
sum(round(c(3.6, 4.1, 5.8, 8.0)))))
round(c(1.1, 7.1, 5.4, 2.7))
1 7 5 3
round(c(3.6, 4.1, 5.8, 8.0))
4 4 6 8
v1 <- c(1.1, -7.1, 5.4, -2.7)
v2 <- c(-3.6, 4.1, 5.8, -8.0)
mean(c(sum(round(abs(v1))), sum(round(abs(v2)))))
mean(c(sum(c(1, 7, 5, 3)),
sum(c(4, 4, 6, 8))))
sum(c(1, 7, 5, 3))
16
sum(c(4, 4, 6, 8))
22
mean(c(16, 22))
19
v1 <- c(1.1, -7.1, 5.4, -2.7)
v2 <- c(-3.6, 4.1, 5.8, -8.0)
mean(c(sum(round(abs(v1))), sum(round(abs(v2)))))
19
li <- list(log = TRUE,
ch = "hello",
int_vec = sort(rep(seq(8, 2, by = -2), times = 2)))
sort(rep(seq(8, 2, by = -2), times = 2)))
li <- list(log = TRUE,
ch = "hello",
int_vec = sort(rep(seq(8, 2, by = -2), times = 2)))
sort(rep(seq(8, 2, by = -2), times = 2)))
seq(1, 10, by = 3)
1 4 7 10
seq(8, 2, by = -2)
8 6 4 2
li <- list(log = TRUE,
ch = "hello",
int_vec = sort(rep(seq(8, 2, by = -2), times = 2)))
sort(rep(c(8, 6, 4, 2), times = 2))
rep(c(8, 6, 4, 2), times = 2)
8 6 4 2 8 6 4 2
rep(c(8, 6, 4, 2), each = 2)
8 8 6 6 4 4 2 2
li <- list(log = TRUE,
ch = "hello",
int_vec = sort(rep(seq(8, 2, by = -2), times = 2)))
sort(c(8, 6, 4, 2, 8, 6, 4, 2))
2 2 4 4 6 6 8 8
sort(c(8, 6, 4, 2, 8, 6, 4, 2), decreasing = TRUE)
8 8 6 6 4 4 2 2
sort(rep(seq(8, 2, by = -2), times = 2))
2 2 4 4 6 6 8 8
li <- list(log = TRUE,
ch = "hello",
int_vec = sort(rep(seq(8, 2, by = -2), times = 2)))
str(li)
List of 3
$ log : logi TRUE
$ ch : chr "hello"
$ int_vec: num [1:8] 2 2 4 4 6 6 8 8
is.list(li)
TRUE
is.list(c(1, 2, 3))
FALSE
li2 <- as.list(c(1, 2, 3))
is.list(li2)
TRUE
unlist(li)
log ch int_vec1 int_vec2 ... int_vec7 int_vec8
"TRUE" "hello" "2" "2" ... "8" "8"
str(append(li, rev(li)))
str(rev(li))
List of 3
$ int_vec: num [1:8] 2 2 4 4 6 6 8 8
$ ch : chr "hello"
$ log : logi TRUE
str(append(li, rev(li)))
List of 3
$ int_vec: num [1:8] 2 2 4 4 6 6 8 8
$ ch : chr "hello"
$ log : logi TRUEstr(append(li, rev(li)))
List of 6
$ log : logi TRUE
$ ch : chr "hello"
$ int_vec: num [1:8] 2 2 4 4 6 6 8 8
$ int_vec: num [1:8] 2 2 4 4 6 6 8 8
$ ch : chr "hello"
$ log : logi TRUE
Intermediate R