问题
I have following data
Data <- data.frame(
X = ("123 234 345 456","222 333 444 555 666" )
)
Data
# X
# 123 234 345 456
# 222 333 444 555 666
A String in one cell, and the length of string is not same in each row
I want the following result
>Result
# X Y Z A B
# 123 234 345 456
# 222 333 444 555 666
one word in one cell
Can anybody help?
回答1:
strsplit is not required here. read.table should work fine. Try:
read.table(text = as.character(Data$X), header=FALSE, fill=TRUE)
You will have to rename the resulting variable names though.
来源:https://stackoverflow.com/questions/17017790/r-how-to-separate-string-in-a-cell-into-several-cells-in-a-row