运行 R 代码时 figa1= figa %>% group_by(ind) %>% summarize(sum = sum(count))
提示报错信息:
Error: Problem with
summarise()
columnsum
.
isum = sum(count)
.
x invalid 'type' (character) of argument
i The error occurred in group 1: ind = >=4.
使用命令 class(figa$count)
:
[1] "character"
发现是因为count列为字符型,而sum函数要求数值型,因此只需要将count转为数值型即可:
figa1= figa %>% mutate(count = as.numeric(as.character(count))) %>% group_by(ind) %>% summarize(total = sum(count))
mutate(count = as.numeric(as.character(count)))
指的是把count转为数值型