Try this: A <- matrix(rnorm(1500),nrow=500) do.call(cbind, lapply(apply(A, 2, acf, lag.max = 10), "[[", "acf"))
On Thu, Aug 7, 2008 at 5:11 AM, rcoder <[EMAIL PROTECTED]> wrote: > > Hi Gary, > > Thanks for your reply. This works fine. Is there any way to send the ACF > data to a matrix, so I could analyse the data in excel for e.g.? > > Thanks, > > rcoder > > > > > > > > > > > > > Ling, Gary (Electronic Trading) wrote: >> >> Hi, here is one possible solution ... >> -gary >> >> ### example ### >> >> # create a 500x3 multi-ts >> A <- matrix(rnorm(1500),nrow=500) >> >> # misc. graphical setting >> par(mfrow=c(ncol(A),1)) >> >> # then our friend -- lapply(split(...)) >> lapply(split(A,col(A)), acf) >> #Or >> lapply(split(A,col(A)), function(ts) acf(ts, lag.max=10)) >> >> >> >> >> >> -----Original Message----- >> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] >> On Behalf Of rcoder >> Sent: Wednesday, August 06, 2008 4:13 PM >> To: r-help@r-project.org >> Subject: [R] using acf() for multiple columns >> >> >> >> Hi everyone, >> >> I'm trying to use the acf() function to calculate the autocorrelation of >> each column in a matrix. The trouble is that I can only seem to get the >> function to work if I extract the data in the column into a separate >> matrix >> and then apply the acf() function to this column. >> >> I have something like this: acf(mat,lag.max=10,na.action=na.pass) >> >> ...but I would really like to apply the function to 'mat' where 'mat' is >> a >> matrix as opposed to a vector. The function actually doesn't return an >> acf >> coefficient, but instead plots the data. So, in addition to handling >> matrices with multiple columns, would anyone know how to coerce the >> function >> to output the underlying data? >> >> Finally, when working with a matrix, is there a way I can specify how >> many >> plots I can display after the function executes? I managed to generate a >> multiple plot when I was experimenting, but the titles suggested the acf >> was >> calculated between adjacent columns in the matrix, which is something I >> was >> puzzled about. >> >> Thanks, >> >> rcoder >> -- >> View this message in context: >> http://www.nabble.com/using-acf%28%29-for-multiple-columns-tp18858672p18 >> 858672.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> 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. >> -------------------------------------------------------- >> >> This message w/attachments (message) may be privileged, confidential or >> proprietary, and if you are not an intended recipient, please notify the >> sender, do not use or share it and delete it. Unless specifically >> indicated, this message is not an offer to sell or a solicitation of any >> investment products or other financial product or service, an official >> confirmation of any transaction, or an official statement of Merrill >> Lynch. Subject to applicable law, Merrill Lynch may monitor, review and >> retain e-communications (EC) traveling through its networks/systems. The >> laws of the country of each sender/recipient may impact the handling of >> EC, and EC may be archived, supervised and produced in countries other >> than the country in which you are located. This message cannot be >> guaranteed to be secure or error-free. This message is subject to terms >> available at the following link: >> http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch >> you consent to the foregoing. >> >> ______________________________________________ >> 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. >> >> > > -- > View this message in context: > http://www.nabble.com/using-acf%28%29-for-multiple-columns-tp18858672p18865946.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ 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.