0

I am a newish R user and have a basic question about na.rm

I have a long list of dataframes, from which I am trying to calculate column means. I have the following code to do this -

results <- lapply(list_of_data_frames, 
             function(x) colMeans(subset(x, select = c(colname1, colname2), na.rm = TRUE)))

This works great but the na.rm piece isn't working, in that I get the result 'NA' for data frames within the list where there is 1 or more NA in the relevant column. Is it positioned correctly in the code?

All help massively appreciated.

Oli

Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56
Ollie Perkins
  • 333
  • 1
  • 12
  • please can you provide a reproducible code (including fake datasets looking like yours). thx – Flecflec Nov 19 '17 at 18:16
  • 4
    You put the `na.rm = TRUE` inside the `subset` call. Move it outside one level of parens, maybe? – joran Nov 19 '17 at 18:19

0 Answers0