I'm trying to write a script to simplify some data analysis, and at some point I need to take averages across some sublists that resemble:
> temp1[[1]]
Replicate Week Treatment aaa bbb ccc ddd eee
C1_T0 1 0 Cold 1 2 3 4 5
C2_T0 2 0 Cold 1 2 3 4 5
C3_T0 3 0 Cold 1 2 3 4 5
C4_T0 4 0 Cold 1 2 3 4 5
H1_T0 1 0 Hot 1 2 3 4 5
H2_T0 2 0 Hot 1 2 3 4 5
H3_T0 3 0 Hot 1 2 3 4 5
H4_T0 4 0 Hot 1 2 3 4 5
To do this, I tried to use to aggregate function to take averages of all other columns as a function of the treatment columns, but this only succeeds for the first column, and then returns numbers that are definitely not the mean.
> temp10 <- aggregate( . ~ Treatment, temp1[[1]], mean)
> temp10
Treatment Replicate Week aaa bbb ccc ddd eee
1 Cold 2.5 1 1 1 1 1 1
2 Hot 2.5 1 1 1 1 1 1
It correctly returns the mean in the replicate column by treatment, but then I'm not quite sure why it's returning something different after that. I would guess that this data structure might be incompatible with the mean function, but then I'm not sure why the replicate mean is correct. Is there a better way to do this type of conditional averaging in lists, or would it be better to try to restructure everything as a dataframe?
sapply(temp1[[1]], class). You want to convert them to integers perhaps. - Rorschach