xref: /Universal-ctags/Units/parser-r.r/r-dataframe.d/input.r (revision 09bc94cd8432980b267e435c322fbcf611c5fec9)
1# Taken from https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/data.frame
2# NOT RUN {
3L3 <- LETTERS[1:3]
4fac <- sample(L3, 10, replace = TRUE)
5(d <- data.frame(x = 1, y = 1:10, fac = fac))
6## The "same" with automatic column names:
7data.frame(n=1, 1:10, sample(L3, 10, replace = TRUE))
8
9is.data.frame(d)
10
11## do not convert to factor, using I() :
12(dd <- cbind(d, char = I(letters[1:10])))
13rbind(class = sapply(dd, class), mode = sapply(dd, mode))
14
15stopifnot(1:10 == row.names(d))  # {coercion}
16
17(d0  <- d[, FALSE])   # data frame with 0 columns and 10 rows
18(d.0 <- d[FALSE, ])   # <0 rows> data frame  (3 named cols)
19(d00 <- d0[FALSE, ])  # data frame with 0 columns and 0 rows
20# }
21