Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.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中拆分多个google表单条目_R_Google Forms - Fatal编程技术网

在R中拆分多个google表单条目

在R中拆分多个google表单条目,r,google-forms,R,Google Forms,我有一个csv文件,其中包含一个在线谷歌表单的结果,我正在使用该表单在R中创建图表。表单上有一个问题允许多个响应,人们可以在一个响应中写入。谷歌表单创建CSV的方式是将所有答案放在一行中。以下是几行的示例: 日期 治疗的改变 1/4 开始服用新药,改变剂量 1/5 开始服用新药 1/6 停止用药,开始新的用药,新的诊断 1/7 新诊断 下面是一种使用tidyr::分隔行的方法: library(tidyverse) separated.data <- data %>% sepa

我有一个csv文件,其中包含一个在线谷歌表单的结果,我正在使用该表单在R中创建图表。表单上有一个问题允许多个响应,人们可以在一个响应中写入。谷歌表单创建CSV的方式是将所有答案放在一行中。以下是几行的示例:

日期 治疗的改变 1/4 开始服用新药,改变剂量 1/5 开始服用新药 1/6 停止用药,开始新的用药,新的诊断 1/7 新诊断
下面是一种使用
tidyr::分隔行的方法:

library(tidyverse)
separated.data <- data %>% 
  separate_rows(Change.in.treatment,sep = ", ")
separated.data
# A tibble: 7 x 2
  Date  Change.in.treatment   
  <chr> <chr>                 
1 1/4   Started new medication
2 1/4   changed dose          
3 1/5   Started new medication
4 1/6   Stopped medication    
5 1/6   Started new medication
6 1/6   New diagnosis         
7 1/7   New diagnosis  

样本数据:

data <- structure(list(Date = c("1/4", "1/5", "1/6", "1/7"), Change.in.treatment = c("Started new medication, changed dose", 
"Started new medication", "Stopped medication, Started new medication, New diagnosis", 
"New diagnosis")), class = "data.frame", row.names = c(NA, -4L
))
数据
data <- structure(list(Date = c("1/4", "1/5", "1/6", "1/7"), Change.in.treatment = c("Started new medication, changed dose", 
"Started new medication", "Stopped medication, Started new medication, New diagnosis", 
"New diagnosis")), class = "data.frame", row.names = c(NA, -4L
))