R: How to separate string in a cell into several cells in a row?

本小妞迷上赌 提交于 2019-12-08 03:41:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!