Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 按分隔符拆分字符串列,然后在分隔符中变为单列_R_String_Dplyr_Mutate - Fatal编程技术网

R 按分隔符拆分字符串列,然后在分隔符中变为单列

R 按分隔符拆分字符串列,然后在分隔符中变为单列,r,string,dplyr,mutate,R,String,Dplyr,Mutate,这个问题可能已经存在了,但我最大的问题是如何表达这个问题,所以如果你能给我指出这个帖子的答案,我将不胜感激 我有一个数据框: test <- data.frame(A = c("A", "B"), B = c("This is a long string", "This is another long string")) A B 1 A This is a long string

这个问题可能已经存在了,但我最大的问题是如何表达这个问题,所以如果你能给我指出这个帖子的答案,我将不胜感激

我有一个数据框:

test <- data.frame(A = c("A", "B"), 
                   B = c("This is a long string", "This is another long string"))

  A                           B
1 A       This is a long string
2 B This is another long string
我们可以使用单独的行


默认情况下,sep将自动拾取空格或其他非字母数字字符。如果需要特定,则指定sep参数

Akrun的答案非常好。如果您不使用dplyr或tidyr软件包,也可以使用splitstackshape::CSplitest,B,,long。@可能不需要删除dupe,因为dupe有助于在谷歌搜索时轻松找到答案
   A       B
1  A    This
2  A      is
3  A       a
4  A    long
5  A  string
6  B    This
7  B      is
8  B another
9  B    long
10 B  string
library(tidyr)
test %>%
   separate_rows(B)
#   A       B
#1  A    This
#2  A      is
#3  A       a
#4  A    long
#5  A  string
#6  B    This
#7  B      is
#8  B another
#9  B    long
#10 B  string