簡體   English   中英

如何用 NA 填充空的 0 xn tibble

[英]How to fill empty 0 x n tibble with NA

I am using the gender package in R and unfortunately the gender function in that package returns blank tibbles when it cannot classify a name as male or female.

Is there a "purrr"- style way to apply the gender function so that empty tibbles of size nxm are replaced by NAs of size nxm in my output, so as to keep the row-size of the inputs and outputs to the gender function equal ?

我想找到一個不涉及為性別 function (如果可能)編寫包裝器的解決方案。

我會通過將名稱存儲在數據框列中來解決此問題,然后將gender()的結果連接回原始數據。

例如:

library(gender)

mydata <- data.frame(name = c("Neil", "Askey"), stringsAsFactors = FALSE)

merge(mydata, gender(mydata$name), all = TRUE)

結果:

   name proportion_male proportion_female gender year_min year_max
1 Askey              NA                NA   <NA>       NA       NA
2  Neil          0.9964            0.0036   male     1932     2012

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM