Re: [R] How to replace a column in a data frame with another one with a different size

2012-07-08 Thread arun
Hi, As the error says, the replacements should have equal number of rows. You can either do it adding NAs, df$V1<-c(NA,rollapply(df$V1,3,mean),NA) df    V1 1  NA 2   2 3   3 4   4 5   5 6   6 7   7 8   8 9   9 10 NA #or, #use any of these #as Michael suggested df2<-rollapply(df,3,mean,fill=NA)

Re: [R] How to replace a column in a data frame with another one with a different size

2012-07-08 Thread R. Michael Weylandt
Your On Sun, Jul 8, 2012 at 12:22 PM, Stathis Kamperis wrote: > 2012/7/8 Michael Weylandt : >> >> >> On Jul 8, 2012, at 9:31 AM, Stathis Kamperis wrote: >> >>> Hello everyone, >>> >>> I have a dataframe with 1 column and I'd like to replace that column >>> with a moving average. >>> Example: >>>

Re: [R] How to replace a column in a data frame with another one with a different size

2012-07-08 Thread Michael Weylandt
On Jul 8, 2012, at 9:31 AM, Stathis Kamperis wrote: > Hello everyone, > > I have a dataframe with 1 column and I'd like to replace that column > with a moving average. > Example: > >> library('zoo') >> mydat <- seq_len(10) >> mydat > [1] 1 2 3 4 5 6 7 8 9 10 >> df <- data.frame("V1"