我在R中有一个data.frame,为了简单起见,该数据框只有一列需要分离。它长这样:
V1
Value_is_the_best_one
This_is_the_prettiest_thing_I've_ever_seen
Here_is_the_next_example_of_what_I_want
我的真实数据非常庞大(数百万行),因此我想使用tidyr的separate函数(因为它非常快)仅分离出前几个实例。我希望结果如下:
V1 V2 V3 V4
Value is the best_one
This is the prettiest_thing_I've_ever_seen
Here is the next_example_of_what_I_want
正如您所看到的,分隔符是_
,V4列可以有不同数量的分隔符。我想保留V4(不要丢弃它),但不必担心里面有多少内容。始终会有四列(即我的行中没有只包含V1-V3的行)。
这是我一直在使用的起始tidyr命令:
separate(df, V1, c("V1", "V2", "V3", "V4"), sep="_")
这将消除V4(并发出警告,但这不是最大的问题)。
extra = "merge"
吗? - aosmith