0

I'm working with a dataset that looks like what is shown below. Now I know that this is not the type of format that R likes. I know how to tidy up the data, but then I'm not sure what I'd do in order to obtain an F statistic for each unique_id, which is my goal. Is there an easy way to do that? Otherwise is there a way I could use some type of apply function to tidy up each row independently, perform, the anova, and then add F statistics as a new column?

unique_id   heart   heart   heart   kidney  kidney  kidney  cortex  cortex  cortex
373020.8    1.39    1.18    1.30    2.71    2.96    2.52    1.97    1.67    1.44
371588.9    1.93    2.35    2.50    2.54    1.63    2.23    2.68    2.89    1.86
367772.8    0.42    0.51    0.97    1.02    0.03    0.82    0.01    0.90    1.01
Dason
  • 60,663
  • 9
  • 131
  • 148

1 Answers1

0

I'm partial to data.tables and you can easily do this with a DT after melting your data. Here's my take, with DT as your data.table containing the info you provided.

DT <- dt<- melt(dt, 
      id.vars = c("unique_id"),
      measure.vars = c("heart","cortex","kidney"))

DT[,fstat:=summary(aov(value~variable))[[1]][1,"F value"],by=unique_id]

This calculates the F-Stat by unique_id and should work.

C. Dubois
  • 16
  • 1