I created DT putting the values in a table:
a <- 2
b <- 20
c <- 0.3
DT <- data.table(a, b, c)
let's assume that I have only the DT generated. How can from DT generate a, b, c (single values)
Thanks and best regards, SH
I created DT putting the values in a table:
a <- 2
b <- 20
c <- 0.3
DT <- data.table(a, b, c)
let's assume that I have only the DT generated. How can from DT generate a, b, c (single values)
Thanks and best regards, SH
With $
or indicating the "cell" in the table. There are many ways to do this.
library(data.table)
a <- 2
b <- 20
c <- 0.3
DT <- data.table(a, b, c)
DT
> DT
a b c
1: 2 20 0.3
x <- DT$a
y <- DT$b
z <- DT$c
DT2 <- data.table(x, y, z)
DT2
> DT2
x y z
1: 2 20 0.3
xa <- DT[1,1]
yb <- DT[1,2]
zc <- DT[1,3]
DT3 <- data.table(xa, yb, zc)
DT3
> DT3
a b c
1: 2 20 0.3
This is basic R knowledge. I suggest you do a basic course (try install.packages(swirl)
, or datacamp) and pay attention to the basic subsetting parts.