Hi, Try this:
res1<-do.call(cbind,t(sapply(res,c))[,1]) #get the acf values only. Assuming that is what you wanted. write.csv(res1,"AMSacf.csv",row.names=FALSE) A.K. ________________________________ From: Zilefac Elvis <[email protected]> To: arun <[email protected]> Sent: Monday, June 24, 2013 1:00 PM Subject: Re: [R] Apply acf to data frame containing 'NA' Hi AK, How can I write the 'res' output to file? Attached is my data. dat1<-AMS1[,-1] pdf("AMS1_acf.pdf") res<-lapply(dat1,function(x)acf(x,na.action=na.pass)) dev.off() I tried something like this: data<-as.data.frame(t(sapply(res,c))) but it did not work. I would like to export the file and store in column mood. Thanks, Atem. ________________________________ From: arun <[email protected]> To: Zilefac Elvis <[email protected]> Sent: Sunday, June 23, 2013 2:33 PM Subject: Re: [R] Apply acf to data frame containing 'NA' HI Atem, No problem. Arun ________________________________ From: Zilefac Elvis <[email protected]> To: arun <[email protected]> Sent: Sunday, June 23, 2013 4:30 PM Subject: Re: [R] Apply acf to data frame containing 'NA' Hi AK, Thanks so much for the fruitful correction. AE. ________________________________ From: arun <[email protected]> To: Zilefac Elvis <[email protected]> Cc: "[email protected]" <[email protected]> Sent: Sunday, June 23, 2013 1:11 PM Subject: Re: [R] Apply acf to data frame containing 'NA' HI Atem, ________________________________ From: Hannah Barron <[email protected]> To: Zilefac Elvis <[email protected]> Cc: R help <[email protected]> Sent: Sunday, June 23, 2013 2:04 PM Subject: Re: [R] Apply acf to data frame containing 'NA' HI, This makes more sense. Sorry, I didn't check the ?acf() before I send the reply. lapply(dat1,function(x)acf(x,na.action=na.pass)) A.K. Hi, The acf function requires that you specify how to deal with NAs in your data. By default, it uses na.fail ("Error in *na.fail.default*(as.ts(x)) : missing values in object). Try using na.action=na.pass as an argument. While this will pass over your NAs, make sure that you understand how that will affect your results. See the acf R documentation for further explanation. Good luck, H On Sun, Jun 23, 2013 at 1:51 PM, Zilefac Elvis <[email protected]>wrote: > Hi, > Thanks so much for the quick reply. > It worked on your data but failed on mine. > Attached is my data. > I received this error: > "Error in acf(na.omit(x)) : 'lag.max' must be at least 0 > In addition: Warning message: > In split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) : > data length is not a multiple of split variable" > > AE. > > > ________________________________ > From: arun <[email protected]> > To: Zilefac Elvis <[email protected]> > Cc: R help <[email protected]> > Sent: Sunday, June 23, 2013 11:41 AM > Subject: Re: [R] Apply acf to data frame containing 'NA' > > > Hi, > May be this helps: > set.seed(24) > A <- matrix(sample(c(NA,rnorm(1500)),1500,replace=FALSE),nrow=500) > par(mfrow=c(ncol(A),1)) > lapply(split(A,col(A)),function(x) acf(na.omit(x))) > A.K. > > > > > ----- Original Message ----- > From: Zilefac Elvis <[email protected]> > To: "[email protected]" <[email protected]> > Cc: > Sent: Sunday, June 23, 2013 1:29 PM > Subject: [R] Apply acf to data frame containing 'NA' > > Hi, > I have a data frame with each column representing a separate site. > Following this code, I can apply acf to all columns in A. 'A' contains > randomly generated data. > > A <- matrix(rnorm(1500),nrow=500) > par(mfrow=c(ncol(A),1)) > > lapply(split(A,col(A)), acf) > > #OR > lapply(split(A,col(A)), function(snow) acf(snow, lag.max=5)) > > > Problem: Some of my data contains 'NA' in some of the columns. I get this > error > "Error in na.fail.default(as.ts(x)) : missing values in object" > How can I resolve this problem? > > Thanks. > AE. > [[alternative HTML version deleted]] > > ______________________________________________ > [email protected] 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. > > ______________________________________________ > [email protected] 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. > > [[alternative HTML version deleted]] ______________________________________________ [email protected] 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. ______________________________________________ [email protected] 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.

