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.








________________________________
From: Irucka Embry <iruc...@mail2world.com>
To: smartpink...@yahoo.com 
Cc: r-help@r-project.org 
Sent: Thursday, March 7, 2013 1:50 AM
Subject: Re: [R] multiple plots and looping assistance requested (revised codes)


Hi Arun, that worked perfectly for the smaller data set, but it has failed to 
plot in the whole data set where I have missing columns (either 1 or 2 columns 
missing).

How can I ask any NAs not to be plotted? I have attempted to use 
na.omit(temper2[[i]]), but it did not work. See below:

pdf("SeasonalFluxComparisonDataSet.pdf")
par(mfrow=c(1,2))
lapply(names(temper2),function(i) lapply(na.omit(temper2[[i]]),function(x) 
{plot(x[,1],x[,2],main="Seasonal Flux 
Sum",sub=paste(i,colnames(x)[2],sep="_"),xlab="Calendar Year 
Timesteps",ylab="Total Flux (kg/season)");lines(x[,1],x[,2])}))
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
> dev.off()

> options("na.action")
$na.action
[1] "na.omit"

Thank you for your quick responses.

Irucka


<-----Original Message-----> 
>From: arun [smartpink...@yahoo.com]
>Sent: 3/6/2013 11:38:37 PM
>To: iruc...@mail2world.com
>Cc: r-help@r-project.org
>Subject: Re: [R] multiple plots and looping assistance requested (revised 
>codes)
>
>HI,
>Try this:
> temp1<-lapply(temp,function(x) x[complete.cases(x),])
> temp2<-lapply(temp1,function(tempNew) lapply(names(tempNew)[-1], 
> function(i){x1<-
>cbind(tempNew[,1],tempNew[,i]); colnames(x1)<- c("CYEAR_DECIMAL",i);x1}))
>pdf("Irucka3.pdf")
> par(mfrow=c(1,2))
>lapply(names(temp2),function(i) lapply(temp2[[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.
>
>
>
>
>
>
>________________________________
>From: Irucka Embry <iruc...@mail2world.com>
>To: smartpink...@yahoo.com 
>Cc: r-help@r-project.org 
>Sent: Wednesday, March 6, 2013 11:49 PM
>Subject: Re: [R] multiple plots and looping assistance requested (revised 
>codes)
>
>
>Hi Arun, thank you for your assistance.
>
>I have successfully ran your suggested revised code (with some minor changes). 
>Thank-you very much!
>
>Is there a way to print either "load_00600_W" or "load_00600_F" after "sub = 
>i" for each plot?
>
>For example, can the subtitle be "02143500 load_00600_W" which is included in 
>temp2?
>
>> dput(temp2)
>structure(list(`02143500` = structure(list(load_00600_W = 
>structure(c(2000.875, 
>2001.125, 2001.375, 2001.625, 2001.875, 2002.125, 2002.375, 2002.625, 
>2002.875, 2003.125, 2003.375, 2003.625, 2003.875, 2004.125, 2004.375, 
>2004.625, 227675.73764, 92777.682029, 84827.680295, 193298.65669, 
>170799.05034, 103666.8759, 107485.71333, 213765.87505, 472307.65662, 
>799500.99994, 754868.43185, 454078.02653, 171521.77777, 265827.90007, 
>120401.25989, 194000.26057), .Dim = c(16L, 2L), .Dimnames = list(
>NULL, c("CYEAR_DECIMAL", "x"))), load_00600_F = structure(c(2000.875, 
>2001.125, 2001.375, 2001.625, 2001.875, 2002.125, 2002..375, 2002.625, 
>2002.875, 2003.125, 2003.375, 2003.625, 2003.875, 2004.125, 2004.375, 
>2004.625, 4202.7437226, 16214.840538, 7371.9290209, 3114.1090754, 
>2464.1114951, 9380.6352081, 3859.2809055, 901.86146915, 22377.413599, 
>53563.26564, 148264.35049, 103538.36278, 18142.045363, 14672.031667, 
>18796.93618, 75313.330193), .Dim = c(16L, 2L), .Dimnames = list(
>NULL, c("CYEAR_DECIMAL", "x")))), .Names = c("load_00600_W", 
>"load_00600_F")), `02169000` = structure(list(load_00600_W = 
>structure(c(2000..875, 
>2001.125, 2001.375, 2001.625, 2001.875, 2002.125, 2002.375, 2002.625, 
>2002.875, 2003.125, 2003.375, 2003.625, 2003.875, 2004.125, 2004.375, 
>2004.625, 61152.4563009734, 3087159.69237187, 83271.1072869206, 
>78182.9098615795, 10344.3815353876, 2246.4450929669, 989.220241325, 
>2318.3488271707, 24134.6766402373, 34350.75952138, 39041.6413152116, 
>28188.925323908, 2281.7849286464, 1756.7094755792, 357.3578073865, 
>238.1185010405), .Dim = c(16L, 2L), .Dimnames = list(NULL, c("CYEAR_DECIMAL", 
>"x"))), load_00600_F = structure(c(2000.875, 2001.125, 2001.375, 
>2001.625, 2001.875, 2002.125, 2002.375, 2002.625, 2002.875, 2003.125, 
>2003.375, 2003.625, 2003.875, 2004.125, 2004.375, 2004.625, 3940.9979246, 
>14888.612602, 5551.1377638, 5055.93881, 1689.0656165, 1436.5965696, 
>849.85774965, 879.76270422, 11452.39104, 62140.01855, 67190.304212, 
>47562.345621, 3535..1744243, 21923.947402, 2059.0406953, 1685.1384101
>), .Dim = c(16L, 2L), .Dimnames = list(NULL, c("CYEAR_DECIMAL", 
>"x")))), .Names = c("load_00600_W", "load_00600_F")), `02172300` = 
>structure(list(
>load_00600_W = structure(c(2001.875, 2002.125, 2002.375, 
>2002.625, 2002.875, 2003.125, 2003.375, 2003.625, 2003.875, 
>2004.125, 2004.375, 2004.625, 16150.219744, 18927.53716, 
>15884.341197, 14102.537116, 11611.582491, 14662.106089, 10576.561683, 
>7699.1718611, 19837.60763, 22396.338619, 34876.278129, 23822.715775
>), .Dim = c(12L, 2L), .Dimnames = list(NULL, c("CYEAR_DECIMAL", 
>"x"))), load_00600_F = structure(c(2001.875, 2002.125, 2002.375, 
>2002.625, 2002.875, 2003.125, 2003.375, 2003.625, 2003.875, 
>2004.125, 2004.375, 2004.625, 899.46439731, 1667.869248, 
>952.12246929, 543.12231908, 1663.8731209, 3123.5771201, 4338.1307758, 
>4469.2046052, 2642.983822, 2863.529214, 2131.6573312, 2476.4154125
>), .Dim = c(12L, 2L), .Dimnames = list(NULL, c("CYEAR_DECIMAL", 
>"x")))), .Names = c("load_00600_W", "load_00600_F")), `21SC60WQ.CW-206` = 
>structure(list(
>load_00600_W = structure(c(2001.875, 2002.125, 2002.375, 
>2002.625, 23693281.5300403, 66710782.7389879, 49036165.5298238, 
>27086129.9582558), .Dim = c(4L, 2L), .Dimnames = list(NULL, 
>c("CYEAR_DECIMAL", "x"))), load_00600_F = structure(c(2001.875, 
>2002.125, 2002.375, 2002.625, 145481.6737, 370915.04829, 
>282387.90945, 179357.3242), .Dim = c(4L, 2L), .Dimnames = list(
>NULL, c("CYEAR_DECIMAL", "x")))), .Names = c("load_00600_W", 
>"load_00600_F"))), .Names = c("02143500", "02169000", "02172300", 
>"21SC60WQ.CW-206"))
>
>
>I have included the successful code below:
>
>temp = read.funkyfile("sitesmore.csv", "station_id", header=TRUE, sep="\t")
>temp1<-lapply(temp,function(x) x[complete.cases(x),])
>temp2<-lapply(temp1,function(tempNew) lapply(tempNew[,-1],function(x) {x1<-
>cbind(CYEAR_DECIMAL=tempNew[,1],x)}))
>pdf("Irucka2.pdf")
>par(mfrow=c(1,2))
>lapply(names(temp2),function(i) lapply(temp2[[i]],function(x) 
>{plot(x[,1],x[,2],main="Seasonal Flux 
>Sum",sub=i,xlab="Calendar Year Timesteps",ylab="Total Flux 
>(kg/season)");lines(x[,1],x[,2])}))
>dev.off()
>
>Thank you.
>
>Irucka
> _______________________________________________________________
Get the Free email that has everyone talking at http://www.mail2world.com
Unlimited Email Storage – POP3 – Calendar – SMS – Translator – Much More!

Attachment: Irucka2.pdf
Description: Adobe PDF document

Attachment: Irucka3.pdf
Description: Adobe PDF document

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to