Reputation: 55
I have lists:
list[30] list of length 30
[[1]] character[3] '10' '20' '30'
[[2]] character[3] '30' '40' '50'
[[3]] character[3] '60' '70' '80'
.... ........... ..............
How can this be converted to data.table?
What I want to get:
| f1 |
|-------|
| '10' '20' '30|
|'30' '40' '50'|
|'60' '70' '80'|
Updated:
dt <- lapply(strsplit(df, " "), function(x) as.character(p.adjust(as.numeric(x))))
dput():
list(c("10", "20", "30"), c("40", "50", "60"
), c("70", "80", "90"))
Upvotes: 1
Views: 82
Reputation: 388982
You can try :
val <- list(c("10", "20", "30"), c("40", "50", "60"), c("70", "80", "90"))
result <- data.table::data.table(f1 = lapply(val, as.numeric))
result
# f1
#1: 10,20,30
#2: 40,50,60
#3: 70,80,90
str(result)
#Classes ‘data.table’ and 'data.frame': 3 obs. of 1 variable:
# $ f1:List of 3
# ..$ : num 10 20 30
# ..$ : num 40 50 60
# ..$ : num 70 80 90
# - attr(*, ".internal.selfref")=<externalptr>
Upvotes: 2