Yen Ngo
2006-Oct-15 20:22 UTC
[R] how can i compute the average of three blocks for each column ?
Dear all, I want to compute the average of the three blocks for each x-variable which is equal slide in the code below. How can I do that ? block x1 x2 x3 x4 x5 1 23 22 23 24 23 1 21 25 26 21 39 1 23 24 22 23 23 2 20 21 23 24 28 2 32 23 34 24 26 2 19 34 34 13 34 3 12 32 ยด 23 34 19 3 23 24 25 26 27 3 12 78 23 24 24 # read table of data for this slide=(x1) a<-read.table(file = slide[i],header=T,sep='\t',na.strings="NA") #length(a$ID) #Eleminate Neg. and Pos. controls from the dataset. The logical negation of the "%in%" function, #tells subset to only select those row where the "ID" column does not contain either "empty" or "none" new <- subset(a,!ID %in% c("empty","none"," ")) #length(new$ID) #new[1:20,c(1,4,5,9)] #five first columns give position identifiers, include a column with block layout=new[,1:5] layout[1:30,] #9th columns which give the median foreground =values of x-variables fg1=as.matrix(new[,9]) length(fg1) mean(fg1) # calculate the mean of x1 #### I try to do something like :########## block1=fg1[layout$Block==1,] block2=fg1[layout$Block==1,] block2=fg1[layout$Block==1,] average=(block1+block2+block3)/3 but it did not work. ################## How can i calculate the means of remaining x_variables? ######### Read data for the remaining slides =x2,x3,x4,x5 ########### for (i in 2:num.slides){ na1 <- strsplit(na[[i]][k],".txt") na2 <- strsplit(na1[[1]][1],"-") bat=na2[[1]][1] sli=na2[[1]][2] nslide <- cbind(nslide,as.numeric(sli)) # nslide is a vector giving the number of the slide in the batch # read table of data for this slide a<-read.table(file=slide[i],header=T,sep='\t',na.strings="NA") new<- subset(a,!ID %in% c("empty","none"," ")) # append FG data to the matrices containing the slides already read fg1=cbind(fg1,as.matrix(new[,9])) } colnames(fg1)=nslide fg<-data.frame(peptide=c(new$Name),fg1) fg <- edit(fg) ##### Another question : I have three graphs which are displayed one after one with a large space between them. Can I move these graph closer each other by making them bigger and how ? Below is the code that i have written for plotting the graphs. par(mfrow=c(3,1)) for (j in 1:3) { boxplot(split(pos$y[pos$Block==j],pos$Slide[pos$Block==j]), col="lightgray", cex=.65, outline=TRUE, main=paste("Positive Controls Block",j)) } Thank you for your help, Regards, Yen [[alternative HTML version deleted]]
Petr Pikal
2006-Oct-17 10:00 UTC
[R] how can i compute the average of three blocks for each column ?
Hi I haven't seen any answer yet so I try>From your not very clear explanation I suspect you want to do someblock aggregation> testblock x1 x2 x3 x4 x5 1 1 23 22 23 24 23 2 1 21 25 26 21 39 3 1 23 24 22 23 23 4 2 20 21 23 24 28 5 2 32 23 34 24 26 6 2 19 34 34 13 34 7 3 12 32 23 34 19 8 3 23 24 25 26 27 9 3 12 78 23 24 24> by(test[,-1], test$block, mean)test$block: 1 x1 x2 x3 x4 x5 22.33333 23.66667 23.66667 22.66667 28.33333 ----------------------------------------------------------------------------------------------------- test$block: 2 x1 x2 x3 x4 x5 23.66667 26.00000 30.33333 20.33333 29.33333 ----------------------------------------------------------------------------------------------------- test$block: 3 x1 x2 x3 x4 x5 15.66667 44.66667 23.66667 28.00000 23.33333> aggregate(test[,-1], list(test$block), mean)Group.1 x1 x2 x3 x4 x5 1 1 22.33333 23.66667 23.66667 22.66667 28.33333 2 2 23.66667 26.00000 30.33333 20.33333 29.33333 3 3 15.66667 44.66667 23.66667 28.00000 23.33333>Regarding your second question with plotting see arguments in par, especially mar or mai. HTH Petr On 15 Oct 2006 at 22:22, Yen Ngo wrote: Date sent: Sun, 15 Oct 2006 22:22:19 +0200 (CEST) From: Yen Ngo <yen_h_ngo at yahoo.se> To: r-help at stat.math.ethz.ch Subject: [R] how can i compute the average of three blocks for each column ?> Dear all, > > > I want to compute the average of the three blocks for each > x-variable which is equal slide in the code below. How can I do that > ? > > > block x1 x2 x3 x4 x5 > 1 23 22 23 24 23 > 1 21 25 26 21 39 > 1 23 24 22 23 23 > 2 20 21 23 24 28 > 2 32 23 34 24 26 > 2 19 34 34 13 34 > 3 12 32 ? 23 34 19 > 3 23 24 25 26 27 > 3 12 78 23 24 24 > > > # read table of data for this slide=(x1) > a<-read.table(file = slide[i],header=T,sep='\t',na.strings="NA") > #length(a$ID) #Eleminate Neg. and Pos. controls from the dataset. > The logical negation of the "%in%" function, #tells subset to only > select those row where the "ID" column does not contain either > "empty" or "none" new <- subset(a,!ID %in% c("empty","none"," ")) > #length(new$ID) #new[1:20,c(1,4,5,9)] > > > #five first columns give position identifiers, include a column with > block layout=new[,1:5] layout[1:30,] > > #9th columns which give the median foreground =values of x-variables > fg1=as.matrix(new[,9]) length(fg1) mean(fg1) # calculate the mean > of x1 > > > > #### I try to do something like :########## > > block1=fg1[layout$Block==1,] > block2=fg1[layout$Block==1,] > block2=fg1[layout$Block==1,] > average=(block1+block2+block3)/3 > > but it did not work. > > ################## How can i calculate the means of remaining > x_variables? ######### Read data for the remaining slides > =x2,x3,x4,x5 ########### > > for (i in 2:num.slides){ > na1 <- strsplit(na[[i]][k],".txt") > na2 <- strsplit(na1[[1]][1],"-") > bat=na2[[1]][1] > sli=na2[[1]][2] > nslide <- cbind(nslide,as.numeric(sli)) > # nslide is a vector giving the number of the slide in the batch # > read table of data for this slide > a<-read.table(file=slide[i],header=T,sep='\t',na.strings="NA") new<- > subset(a,!ID %in% c("empty","none"," ")) # append FG data to the > matrices containing the slides already read > fg1=cbind(fg1,as.matrix(new[,9])) } > > colnames(fg1)=nslide > fg<-data.frame(peptide=c(new$Name),fg1) > fg <- edit(fg) > > > > ##### Another question : I have three graphs which are displayed one > after one with a large space between them. Can I move these graph > closer each other by making them bigger and how ? Below is the code > that i have written for plotting the graphs. > > par(mfrow=c(3,1)) > for (j in 1:3) > { > boxplot(split(pos$y[pos$Block==j],pos$Slide[pos$Block==j]), > col="lightgray", cex=.65, outline=TRUE, main=paste("Positive Controls > Block",j)) } > > > Thank you for your help, > Regards, > > Yen > > [[alternative HTML version deleted]] > >Petr Pikal petr.pikal at precheza.cz