Почему я получаю NA, даже если я использовал na.rm = "TRUE"? - PullRequest
0 голосов
/ 08 октября 2018

Не могли бы вы помочь мне, почему я все еще получаю NA, даже если я использовал lapply(HiringDateInfo$YrsEmp,mean,na.rm = "TRUE")?

> lapply(HiringDateInfo$YrsEmp,mean,na.rm = "TRUE")
[[1]]
[1] NA

[[2]]
[1] NA

[[3]]
[1] NA

[[4]]
[1] NA

[[5]]
[1] NA

Warning messages:
1: In mean.default(X[[i]], ...) :
  argument is not numeric or logical: returning NA
2: In mean.default(X[[i]], ...) :
  argument is not numeric or logical: returning NA
3: In mean.default(X[[i]], ...) :
  argument is not numeric or logical: returning NA
4: In mean.default(X[[i]], ...) :
  argument is not numeric or logical: returning NA
5: In mean.default(X[[i]], ...) :
  argument is not numeric or logical: returning NA

enter image description here

> str(HiringDateInfo)
'data.frame':	5 obs. of  4 variables:
 $ system.record_id: chr  "530eed6dbfb5c1a8e77cb0fc" "5391a88bbfb5c1b1fed0bcf4" "53a0fa3cf1f17922a0287add" "53abd15cf1f179c3e81a3fbe" ...
 $ StartHireDate   :List of 5
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpDate9: Date, format: NA
  .. ..$ EmpDate8: Date, format: NA
  .. ..$ EmpDate7: Date, format: NA
  .. ..$ EmpDate6: Date, format: NA
  .. ..$ EmpDate5: Date, format: NA
  .. ..$ EmpDate4: Date, format: NA
  .. ..$ EmpDate3: Date, format: NA
  .. ..$ EmpDate2: Date, format: NA
  .. ..$ EmpDate1: Date, format: NA
  .. ..$ EmpDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpDate9: Date, format: NA
  .. ..$ EmpDate8: Date, format: NA
  .. ..$ EmpDate7: Date, format: NA
  .. ..$ EmpDate6: Date, format: NA
  .. ..$ EmpDate5: Date, format: NA
  .. ..$ EmpDate4: Date, format: NA
  .. ..$ EmpDate3: Date, format: NA
  .. ..$ EmpDate2: Date, format: NA
  .. ..$ EmpDate1: Date, format: NA
  .. ..$ EmpDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpDate9: Date, format: NA
  .. ..$ EmpDate8: Date, format: NA
  .. ..$ EmpDate7: Date, format: NA
  .. ..$ EmpDate6: Date, format: NA
  .. ..$ EmpDate5: Date, format: NA
  .. ..$ EmpDate4: Date, format: NA
  .. ..$ EmpDate3: Date, format: NA
  .. ..$ EmpDate2: Date, format: NA
  .. ..$ EmpDate1: Date, format: NA
  .. ..$ EmpDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpDate9: Date, format: NA
  .. ..$ EmpDate8: Date, format: NA
  .. ..$ EmpDate7: Date, format: NA
  .. ..$ EmpDate6: Date, format: NA
  .. ..$ EmpDate5: Date, format: NA
  .. ..$ EmpDate4: Date, format: NA
  .. ..$ EmpDate3: Date, format: NA
  .. ..$ EmpDate2: Date, format: NA
  .. ..$ EmpDate1: Date, format: NA
  .. ..$ EmpDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpDate9: Date, format: "2009-03-01"
  .. ..$ EmpDate8: Date, format: "2011-05-01"
  .. ..$ EmpDate7: Date, format: "2011-11-01"
  .. ..$ EmpDate6: Date, format: "2012-04-01"
  .. ..$ EmpDate5: Date, format: "2012-06-01"
  .. ..$ EmpDate4: Date, format: "2012-11-01"
  .. ..$ EmpDate3: Date, format: "2013-06-03"
  .. ..$ EmpDate2: Date, format: NA
  .. ..$ EmpDate1: Date, format: "2014-06-01"
  .. ..$ EmpDate0: Date, format: "2014-11-01"
 $ EndHireDate     :List of 5
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: Date, format: NA
  .. ..$ EmpEndDate8: Date, format: NA
  .. ..$ EmpEndDate7: Date, format: NA
  .. ..$ EmpEndDate6: Date, format: NA
  .. ..$ EmpEndDate5: Date, format: NA
  .. ..$ EmpEndDate4: Date, format: NA
  .. ..$ EmpEndDate3: Date, format: NA
  .. ..$ EmpEndDate2: Date, format: NA
  .. ..$ EmpEndDate1: Date, format: NA
  .. ..$ EmpEndDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: Date, format: NA
  .. ..$ EmpEndDate8: Date, format: NA
  .. ..$ EmpEndDate7: Date, format: NA
  .. ..$ EmpEndDate6: Date, format: NA
  .. ..$ EmpEndDate5: Date, format: NA
  .. ..$ EmpEndDate4: Date, format: NA
  .. ..$ EmpEndDate3: Date, format: NA
  .. ..$ EmpEndDate2: Date, format: NA
  .. ..$ EmpEndDate1: Date, format: NA
  .. ..$ EmpEndDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: Date, format: NA
  .. ..$ EmpEndDate8: Date, format: NA
  .. ..$ EmpEndDate7: Date, format: NA
  .. ..$ EmpEndDate6: Date, format: NA
  .. ..$ EmpEndDate5: Date, format: NA
  .. ..$ EmpEndDate4: Date, format: NA
  .. ..$ EmpEndDate3: Date, format: NA
  .. ..$ EmpEndDate2: Date, format: NA
  .. ..$ EmpEndDate1: Date, format: NA
  .. ..$ EmpEndDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: Date, format: NA
  .. ..$ EmpEndDate8: Date, format: NA
  .. ..$ EmpEndDate7: Date, format: NA
  .. ..$ EmpEndDate6: Date, format: NA
  .. ..$ EmpEndDate5: Date, format: NA
  .. ..$ EmpEndDate4: Date, format: NA
  .. ..$ EmpEndDate3: Date, format: NA
  .. ..$ EmpEndDate2: Date, format: NA
  .. ..$ EmpEndDate1: Date, format: NA
  .. ..$ EmpEndDate0: Date, format: NA
  ..$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: Date, format: "2011-03-30"
  .. ..$ EmpEndDate8: Date, format: "2011-11-30"
  .. ..$ EmpEndDate7: Date, format: "2011-12-30"
  .. ..$ EmpEndDate6: Date, format: "2012-05-30"
  .. ..$ EmpEndDate5: Date, format: "2012-09-30"
  .. ..$ EmpEndDate4: Date, format: "2013-05-30"
  .. ..$ EmpEndDate3: Date, format: "2014-02-15"
  .. ..$ EmpEndDate2: Date, format: "2014-03-30"
  .. ..$ EmpEndDate1: Date, format: "2014-08-30"
  .. ..$ EmpEndDate0: Date, format: NA
 $ YrsEmp          :List of 5
  ..$ :'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate8: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate7: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate6: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate5: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate4: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate3: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate2: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate1: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate0: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  ..$ :'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate8: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate7: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate6: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate5: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate4: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate3: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate2: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate1: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate0: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  ..$ :'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate8: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate7: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate6: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate5: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate4: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate3: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate2: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate1: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate0: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  ..$ :'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate8: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate7: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate6: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate5: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate4: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate3: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate2: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate1: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate0: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  ..$ :'data.frame':	1 obs. of  10 variables:
  .. ..$ EmpEndDate9: 'difftime' num 2.07945205479452
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate8: 'difftime' num 0.583561643835616
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate7: 'difftime' num 0.161643835616438
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate6: 'difftime' num 0.161643835616438
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate5: 'difftime' num 0.331506849315069
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate4: 'difftime' num 0.575342465753425
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate3: 'difftime' num 0.704109589041096
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate2: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate1: 'difftime' num 0.246575342465753
  .. .. ..- attr(*, "units")= chr "days"
  .. ..$ EmpEndDate0: 'difftime' num NA
  .. .. ..- attr(*, "units")= chr "days"

Чтобы придумать YrsEmp, я использовал эту функцию foo <- function(x, y) list((x-y)/365), а затем запустил эту HiringDateInfo$YrsEmp<-mapply(foo, HiringDateInfo$EndHireDate, HiringDateInfo$StartHireDate)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...