所以我有data.frame
dat = data.frame(x = c('Sir Lancelot the Brave', 'King Arthur',
'The Black Knight', 'The Rabbit'), stringsAsFactors=F)
> dat
x
1 Sir Lancelot the Brave
2 King Arthur
3 The Black Knight
4 The Rabbit
我想把它转换成数据框
> dat2
x 1 2 3 4
1 Sir Lancelot the Brave Sir Lancelot the Brave
2 King Arthur King Arthur
3 The Black Knight The Black Knight
4 The Rabbit The Rabbit
strsplit 将数据作为列表返回
sbt <- strsplit(dat$x, " ")
> sbt
[[1]]
[1] "Sir" "Lancelot" "the" "Brave"
[[2]]
[1] "King" "Arthur"
[[3]]
[1] "The" "Black" "Knight"
[[4]]
[1] "The" "Rabbit"
并且 as.data.table 不会在应该的地方创建 NULL 值,而是重复值
> t(as.data.table(sbt))
[,1] [,2] [,3] [,4]
V1 "Sir" "Lancelot" "the" "Brave"
V2 "King" "Arthur" "King" "Arthur"
V3 "The" "Black" "Knight" "The"
V4 "The" "Rabbit" "The" "Rabbit"
我想我真的很想为 as.data.table(x, repeat=FALSE) 提供一个参数,否则我该如何完成这项工作?