【发布时间】:2022-01-17 19:14:28
【问题描述】:
这里是data.frame data 如下,如何转移到wished_data 谢谢!
library(tidyverse)
data <- data.frame(category=c('a','b','a','b','a'),
values=c(1,'A','2','4','B'))
#below code can't work
data %>% group_by(category ) %>%
summarize(sum=if_else(is.numeric(values)>0,sum(is.numeric(values)),paste0(values)))
#below is the wished result
wished_data <- data.frame(category=c('a','a','b','b'),
values=c('3','B','A','4'))
【问题讨论】:
-
为什么是
wished_data[[4,2]]==4?