Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # first i create the new dataframe
- data.mean<- data.frame(matrix(nrows=30))
- # iterate over every third collumn
- for(col in seq(1,length(colnames(data)), by=3)){
- # create a subset from the dataframe and compute the mean of the rows and finally cbind it to the result dataframe
- data.mean <-cbind(data.mean,apply(subset(data, select=seq(col,length.out = 3)),1,mean, na.rm = TRUE))
- # setting the new collumn name to the colname from the old dataset (name of the first replicate)
- colnames(data.mean)[ncol(data.mean)] <- colnames(data)[col]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement