将 data.frame 的列拆分为更多列
Splitting column of a data.frame into more columns
我想将 Test data.frame
的 Out 列拆分为基于空白分隔的列 space .这是我的 MWE。我尝试了 tidyr
包中的 separate
函数和 base
R
中的 strsplit
函数,但无法找出问题所在。
Test <-
structure(list(Out = structure(1:2, .Label = c("t1* -0.4815861 0.3190424 0.2309631",
"t2* 0.9189246 -0.1998455 0.2499412"), class = "factor")),
.Names = "Out", row.names = c(NA, -2L), class = "data.frame")
library(dplyr)
library(tidyr)
Test %>% separate(Out, c("A", "B", "C", "D"), sep = " ")
Error: Values not split into 4 pieces at 1, 2
strsplit(Test$Out, " ")
Error in strsplit(Test$Out, " ") : non-character argument
尝试
Test %>% separate(Out, c("A", "B", "C", "D"), sep = "\s+")
允许多个空格 (\s+
)。
我想将 Test data.frame
的 Out 列拆分为基于空白分隔的列 space .这是我的 MWE。我尝试了 tidyr
包中的 separate
函数和 base
R
中的 strsplit
函数,但无法找出问题所在。
Test <-
structure(list(Out = structure(1:2, .Label = c("t1* -0.4815861 0.3190424 0.2309631",
"t2* 0.9189246 -0.1998455 0.2499412"), class = "factor")),
.Names = "Out", row.names = c(NA, -2L), class = "data.frame")
library(dplyr)
library(tidyr)
Test %>% separate(Out, c("A", "B", "C", "D"), sep = " ")
Error: Values not split into 4 pieces at 1, 2
strsplit(Test$Out, " ")
Error in strsplit(Test$Out, " ") : non-character argument
尝试
Test %>% separate(Out, c("A", "B", "C", "D"), sep = "\s+")
允许多个空格 (\s+
)。