-1

I have a large matrix as a result of using tapply with an INDEX argument of two rows from a dataframe. Most of the matrix is empty (NA).

Here is how I used tapply: latavgs <- tapply(geodata$latitude,geodata[5:6],FUN=mean) where latavgs is my resulting matrix, and geodata is the dataframe mentioned above.

Is there a way to extract only the non-NA elements from latavgs and return them in such a way that I could have the row and column listed, as well as the value? Or is there a better way to use tapply than what I've done, if I want to take the means of all values in geodata that belong to each unique pair of values from geodata[5:6]? I.e., for each unique pair in geodata[5:6] I get one mean.

Thanks for any help.

1 Answers1

0

Really hard to solve this without fully look at your data. Try this: Why does tapply take the subset as NA and not exclude them totally

Community
  • 1
  • 1
12341234
  • 404
  • 5
  • 16