When using aggregate(), I got many NA aoutcomes

Hi, I am using aggregate() to calculate the mean value by group of a data frame called "data"
But I got many NA values in the first few columns and I don`t know how to figure it out.
Thanks for help in advance!

> head(data)
# A tibble: 6 x 16
  listing_id comments WC    Analytic Clout Authentic Tone  WPS   Sixltr   Dic affect posemo
       <dbl> <chr>    <chr> <chr>    <chr> <chr>     <chr> <chr>  <dbl> <dbl>  <dbl>  <dbl>
1          2 "they g~ 13    97.95    99    1.4       25.77 13      7.69  76.9   0      0   
2          3 "no car~ 6     18.82    4.8   1         25.77 6       0     50     0      0   
3      11156 "I was ~ 33    95.64    38.08 99        99    16.5   18.2   93.9   9.09   9.09
4      11156 "I love~ 8     11.86    89.42 74.76     99    8      25    100    12.5   12.5 
5      11156 "Collee~ 51    93.26    34.73 98.01     99    25.5   15.7   86.3  13.7   13.7 
6      11156 "Collee~ 49    98.63    50    46.05     99    16.33  22.4   77.6   8.16   8.16
# ... with 4 more variables: negemo <dbl>, anx <dbl>, anger <dbl>, sad <dbl>
>data_agg<- aggregate(x = data[,3:16],               
          by = list(data$listing_id), 
          .drop = False,
          FUN = mean)                          

> head(data_agg)
  Group.1 WC Analytic Clout Authentic Tone WPS Sixltr    Dic affect posemo negemo anx anger
1       2 NA       NA    NA        NA   NA  NA  7.690 76.920  0.000  0.000  0.000   0     0
2       3 NA       NA    NA        NA   NA  NA  0.000 50.000  0.000  0.000  0.000   0     0
3      10 NA       NA    NA        NA   NA  NA 30.000 30.000  0.000  0.000  0.000   0    NA
4      22 NA       NA    NA        NA   NA  NA 13.640 13.640  0.000  0.000  0.000   0    NA
5     116 NA       NA    NA        NA   NA  NA  9.480  8.620  0.860  0.000  0.000   0    NA
6   11156 NA       NA    NA        NA   NA  NA 18.606 79.682  9.806  9.324  0.122   0     0
  sad
1   0
2   0
3  NA
4  NA
5  NA
6   0

It is because the columns WC to WPS are stored as character vectors, for which mean() gives back NA.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.