如何计算每行数据帧中整数值的数量

时间:2021-04-19 05:49:28

标签: r dataframe dplyr

我有一个如下所示的数据框:

structure(list(Policy_Number = c(81300000293, 81300000455, 81300000536, 
81300000617, 81300000690, 81300000771, 81300000852, 81300000933, 
81300001184, 81300001265), Every_2_Month = c(NA, 1, NA, NA, NA, 
NA, 1, NA, NA, NA), Annual = c(NA, NA, NA, 8, NA, NA, NA, 10, 
NA, NA), Quarterly = c(NA, 1, NA, NA, 43, NA, NA, NA, NA, NA), 
    Semi_Annual = c(NA, NA, 2, NA, NA, NA, NA, NA, NA, NA), Monthly = c(26, 
    NA, NA, 36, NA, 70, 126, NA, 60, 58)), row.names = c(NA, 
-10L), problems = structure(list(row = 292488L, col = "Policy_Number", 
    expected = "a double", actual = "Grand Total", file = "'C:/Users/roozb/Dropbox/Roozbeh-Emad/Life Insurance/2- Original Data/type_of_payment.csv'"), row.names = c(NA, 
-1L), class = c("tbl_df", "tbl", "data.frame")), class = c("tbl_df", 
"tbl", "data.frame"))

我想要做的是创建一个新列,并在其中放置一个数字在数据帧的每一行中出现的总时间。所以结果是:

   Policy_Number Every_2_Month Annual Quarterly Semi_Annual Monthly Total_int
           <dbl>         <dbl>  <dbl>     <dbl>       <dbl>   <dbl>   <dbl>
 1   81300000293            NA     NA        NA          NA      26     1
 2   81300000455             1     NA         1          NA      NA     2
 3   81300000536            NA     NA        NA           2      NA     1   
 4   81300000617            NA      8        NA          NA      36     1 
 5   81300000690            NA     NA        43          NA      NA     1
 6   81300000771            NA     NA        NA          NA      70     1
 7   81300000852             1     NA        NA          NA     126     2
 8   81300000933            NA     10        NA          NA      NA     1
 9   81300001184            NA     NA        NA          NA      60     1
10   81300001265            NA     NA        NA          NA      58     1

0 个答案:

没有答案