Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. # first i create the new dataframe
  2. data.mean<- data.frame(matrix(nrows=30))
  3.  
  4. # iterate over every third collumn
  5. for(col in seq(1,length(colnames(data)), by=3)){
  6.  
  7. # create a subset from the dataframe and compute the mean of the rows and finally cbind it to the result dataframe
  8. data.mean <-cbind(data.mean,apply(subset(data, select=seq(col,length.out = 3)),1,mean, na.rm = TRUE))
  9.  
  10. # setting the new collumn name to the colname from the old dataset (name of the first replicate)
  11. colnames(data.mean)[ncol(data.mean)] <- colnames(data)[col]
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement