【发布时间】:2022-01-18 03:14:21
【问题描述】:
我有以下数据
Year <- c("2021","2021","2021","2021","2021","2021")
Month <- c("8","8","8","8","8","8")
Day <- c("10","15","18","20","22","25")
Hour <- c("171110","171138","174247","183542","190156","190236")
Id_Type <- c("2","2","1","","1","")
Code_Intersecction <- c("340","","","210","750","980")
Data = data.frame(Year,Month,Day,Hour,Id_Type,Code_Intersecction)
我需要计算基础中存在的“”的数量,因为如果它大于 5%,则使用以下值,否则取值为 1,否则为 0
Data_Null = as.data.frame(purrr::map_dbl(Data, .f = function(x){ifelse(round(sum(x == '')/nrow(Data)*100L,3) >= 5, 1, 0)}))
colnames(Data_Null) = "Null"
当我看到数据框时问题就来了,我只需要一列而不是 2;名称和值 0/1
如何让它如下所示
【问题讨论】: