Joining lists then making boxplots
Let's say that I have got two lists:
temp<-c("con.sin.results","sin.results","exp.results")
Temp<-c("[,1:16]","[,17:32]","[,33:48]","[,49:64]")
Each of the variables in temp contain 1000 observations and 64 variables. What i am trying to do is create a double loop so that I can create boxplots based on sample size (so that each boxplot would have 16 boxes, as per Temp) i.e I would get boxplot(con.sin.results[,1:16]), then boxplot(con.sin.results[,17:32]) etc.
With this goal in mind, I've gotten to the following point:
for (l in temp){
for (L in Temp){
windows()
par(mfrow=c(2,2))
A<-noquote(paste(noquote(l),noquote(L),sep=""))
开发者_开发问答boxplot(A)
}
}
Unfortunately, this spits out an error at me:
Error in x[floor(d)] + x[ceiling(d)] : non-numeric argument to binary operator
Where am I going wrong? What should I adjust?
If I understand your question correctly, this is more or less what you want:
bplotforone<-function(mat, groups=list(1:16, 17:32, 33:48, 49:64), newwin=TRUE, mfrow=c(2,2))
{
nr<-nrow(mat)
if(newwin) windows()
par(mfrow=mfrow)
for(curgroup in groups)
{
newres<-as.vector(mat[,curgroup])
newres<-data.frame(vals=newres, grp=rep(seq_along(curgroup), each=nr))
boxplot(vals~grp, data=newres)
}
}
con.sin.results2<-matrix(runif(10*64), ncol=64) #generated some test data here
bplotforone(con.sin.results2)
You can now easily do something like:
listOfResults<-list(con.sin.results,sin.results,exp.results) #note: no quotes!!
for(curres in listOfResults) bplotforone(curres)
This is what my supervisor came up with:
temp<-c("con.sin.results","sin.results","exp.results")
N<-c(50,100,250,500)
con.sin.results<-matrix(runif(100*64),100,64)
sin.results<-matrix(runif(100*64),100,64)
exp.results<-matrix(runif(100*64),100,64)
for (I in temp){
windows()
par(mfrow=c(2,2))
for (n in N){
if (n==50) eval(parse(text=paste("boxplot(",I,"[,1:16])",sep="")))
if (n==100) eval(parse(text=paste("boxplot(",I,"[,17:32])",sep="")))
if (n==250) eval(parse(text=paste("boxplot(",I,"[,33:48])",sep="")))
if (n==500) eval(parse(text=paste("boxplot(",I,"[,49:64])",sep="")))
}
}
精彩评论