R:将单词从一列中提取到不同的列中 [英] R:Extracting words from one column into different columns

查看:76
本文介绍了R:将单词从一列中提取到不同的列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经弄清楚了两个小时. 假设我有一列包含1-4个单词的列,并用空格隔开:

I've been figuring this out for a couple of hours now. Let's say I have a column with 1-4 words, separated by space:

aba bkak absbs
a2aj akls bios
sad
fasa lgk
.
.
.

我希望这些词放在不同的列中,以便于进一步处理.因此,这些单词放在一列中,如何将它们分开?

I would like those words to be in separate columns, for easier further processing. SO instead those words are in one column, how do I get them to separate columns?

感谢您的帮助.

推荐答案

尝试

library(splitstackshape)
cSplit(df1, 'V1', ' ')

library(tidyr)
separate(df1, 'V1', paste0('V', 1:4), sep= ' ', extra='drop')

或使用base R

read.table(text=df1$V1, sep=' ', fill=TRUE)

注意:将列名用作"V1",将数据集用作"df1"

NOTE: Used the column name as 'V1' and dataset as 'df1'

这篇关于R:将单词从一列中提取到不同的列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆