R Error: expecting a single value what does it mean?
R Error: expecting a single value what does it mean?
我在 R 中使用 dplyr 做一个简单的操作并得到 'expecting single value' 错误
test <- data.frame(a=rep("item",3),b=c("step1","step2","step3"))
test%>%group_by(a)%>%(summarize(seq=paste0(b))
我见过类似的线程,但这些用例更复杂,我无法弄清楚为什么这两行不起作用。
由于您只有一组 ("item"),因此 paste0
将获得 b
中三个项目的向量作为输入,并将 return 向量三个字符串,但您的摘要需要一个值(因为只有一组)。您需要 collapse
将 paste0
转换为单个字符串,如下所示:
library(dplyr)
test <- data.frame(a=rep("item",3), b=c("step1","step2","step3"))
test %>% group_by(a) %>% summarize(seq = paste0(b, collapse = ""))
我在 R 中使用 dplyr 做一个简单的操作并得到 'expecting single value' 错误
test <- data.frame(a=rep("item",3),b=c("step1","step2","step3"))
test%>%group_by(a)%>%(summarize(seq=paste0(b))
我见过类似的线程,但这些用例更复杂,我无法弄清楚为什么这两行不起作用。
由于您只有一组 ("item"),因此 paste0
将获得 b
中三个项目的向量作为输入,并将 return 向量三个字符串,但您的摘要需要一个值(因为只有一组)。您需要 collapse
将 paste0
转换为单个字符串,如下所示:
library(dplyr)
test <- data.frame(a=rep("item",3), b=c("step1","step2","step3"))
test %>% group_by(a) %>% summarize(seq = paste0(b, collapse = ""))