Skip to content

multiple plots and looping assistance requested (revised codes)

2 messages · Irucka Embry, arun

#
Hi Irucka,

Regarding the first question.

If you look at the ouput of temp1, it already strips off any NA that was left in the columns.? It is always to give an example dataset that is similar to the real dataset.

Here, I am guessing the situation is similar to this:
temp1<-lapply(temp,function(x) x[complete.cases(x),]) #NA values are removed
temp1[[2]]<- temp1[[2]][1:2] #Some columns are removed
?temp1[[3]]<- temp1[[3]][c(1,3)] # Some columns removed
#Subsetting based on 3 columns and 2 columns
#3 columns

temp3<-temp1[lapply(temp1,ncol)==3]
temp3New<-lapply(temp3,function(x) lapply(names(x)[-1], function(i){x1<-cbind(temp3[,1],temp3[,i]); colnames(x1)<- c("CYEAR_DECIMAL",i);x1}))

pdf("Irucka3.pdf")
par(mfrow=c(1,2))
lapply(names(temp3New),function(i) lapply(temp3New[[i]],function(x) {plot(x[,1],x[,2],main="Fluxmaster versus EGRET/WRTDS \n Seasonal FLux Sum",sub=paste(i,colnames(x)[2],sep="_"),xlab="Calendar Year Timesteps",ylab="Total Flux (kg/season)");lines(x[,1],x[,2])}))
dev.off()
# 2 columns
temp2<-temp1[lapply(temp1,ncol)==2]
temp2New<-lapply(temp2,function(x) lapply(names(x)[-1], function(i){x1<-cbind(temp2[,1],temp2[,i]); colnames(x1)<- c("CYEAR_DECIMAL",i);x1}))

pdf("Irucka2.pdf")
par(mfrow=c(1,1))
lapply(names(temp2New),function(i) lapply(temp2New[[i]],function(x) {plot(x[,1],x[,2],main="Fluxmaster versus EGRET/WRTDS \n Seasonal FLux Sum",sub=paste(i,colnames(x)[2],sep="_"),xlab="Calendar Year Timesteps",ylab="Total Flux (kg/season)");lines(x[,1],x[,2])}))
dev.off()

A.K.