将系数分为R列

将系数分为R列,r,tidyverse,R,Tidyverse,我试图将(tidyr)行文本分隔成单独的单词,因此每列一个单词 数据: 使用的编码: numcols<- make.unique(c(rep("word",10, sep = " ")) ) df<- reportdiagn%>% (separate(reportdiagn$line_text, into = numcols, sep = (""))) 你粘贴的数据不太正确。也

我试图将(tidyr)行文本分隔成单独的单词,因此每列一个单词

数据:

使用的编码:

numcols<- make.unique(c(rep("word",10, sep  = " ")) )

df<- reportdiagn%>%
 (separate(reportdiagn$line_text,
        into = numcols, 
        sep = ("")))

你粘贴的数据不太正确。也许再尝试一次会很好,但我已经尝试重现您的数据。可能不完全一样。我已经将linetext设置为字符串-但我认为下面的代码可以使用字符或因子

select()
中,您不需要引用数据帧,
%>%
已经这样做了,您只需要不带引号的变量名。此外,您的
sep
需要是空格或
\\b
作为单词边界

ID <- c(140, 233, 233)
pdf_name <- factor(c(1, 2, 2),
    labels = c(
        "GBD2016_2_1255_Venezuela_MoH_Epi_2012_9.pdf", 
        "GBD2016_2_1351_Venezuela_MoH_Epi_2014_44.pdf") 
)
keyword <- c("SEGÚN GRUPOS", "SEGÚN GRUPOS", "SEGÚN GRUPOS")
line_text <- c("2000 Gráfico 2 . CASOS DE MALARIA SEGÚN GRUPOS DE EDAD Y SEXO, EPIDEMIOLÓGICA 9 Año 2012", 
               "GRÁFICO 2. CASOS DE MALARIA SEGÚN GRUPOS DE EDAD Y SEXO, HASTA", 
               "GRÁFICO 2. CASOS DE SEGÚN GRUPOS.")
reportdiagn <- data.frame(ID, pdf_name, keyword, line_text)

numcols<- make.unique(c(rep("word",10 )) )

df <- reportdiagn %>%
    separate(line_text,
              into = numcols, 
              sep = " ")

ID Try:
separate(reportdiagn,“line_text”,into=numcols,sep=“”)
顺便说一句,你的示例数据dput格式不正确,你能编辑你的帖子吗:
dput(head(reportdiagn,3))
这只是一个粗略的示例,所以这无关紧要。
`Error in UseMethod("separate_") : 
 no applicable method for 'separate_' applied to an object of class "factor
ID <- c(140, 233, 233)
pdf_name <- factor(c(1, 2, 2),
    labels = c(
        "GBD2016_2_1255_Venezuela_MoH_Epi_2012_9.pdf", 
        "GBD2016_2_1351_Venezuela_MoH_Epi_2014_44.pdf") 
)
keyword <- c("SEGÚN GRUPOS", "SEGÚN GRUPOS", "SEGÚN GRUPOS")
line_text <- c("2000 Gráfico 2 . CASOS DE MALARIA SEGÚN GRUPOS DE EDAD Y SEXO, EPIDEMIOLÓGICA 9 Año 2012", 
               "GRÁFICO 2. CASOS DE MALARIA SEGÚN GRUPOS DE EDAD Y SEXO, HASTA", 
               "GRÁFICO 2. CASOS DE SEGÚN GRUPOS.")
reportdiagn <- data.frame(ID, pdf_name, keyword, line_text)

numcols<- make.unique(c(rep("word",10 )) )

df <- reportdiagn %>%
    separate(line_text,
              into = numcols, 
              sep = " ")