gpt4 book ai didi

r - 如何使用 map_dbl 创建两个变量和过滤器

转载 作者:行者123 更新时间:2023-12-05 09:29:19 25 4
gpt4 key购买 nike

<分区>

我有以下数据

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"

当我看到数据框时,问题就来了,它只需要一列而不是两列;名称和值 0/1

enter image description here

如何让它显示如下

enter image description here

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com