I have a data frame of different samples and technical replicates (AA.1, AA.2, AA.3). Each full sample set (all sample technical replicates) has a measurement, var3, and is repeated for a different var2 (X, Y, or Z). So in total, I have (# of samples)(# of technical replicates)(number of var2) measurements (all possible combinations of var1 x var2 repeated 3 times).
data.frame(
var1=rep(rep(c('AA.1', 'AA.2', 'AA.3', 'BB.1', 'BB.2', 'BB.3'), each=3), 2),
var2=rep(c('X', 'Y'), each=18),
var3=sample(20:40, 36, replace=TRUE)
)
For each var2, I want to average each individual sample's technical replicate. I would like to do this by creating a new data frame that lists the sample name as the row names and 3 columns are the 3 technical replicates. Then I can do rowMeans() and sd(). How is this possible?