Hi,
May be this helps:
lst1<-dlply(data,.(FileNo,ChannelNo),transform,filtered=applyfilter(ChannelB))
?data2<-do.call(rbind,lapply(lst1,function(x){x$filtered<-
as.numeric(x$filtered);x}))
?row.names(data2)<- row.names(data)
head(data,3)
#??????????? Time ChannelA? ChannelB FileNo ChannelNo
#1161 1.83214e-05 4.527559? 6.873434????? 1???????? 1
#1171 2.36814e-05 4.881890 13.602919????? 1???????? 1
#1181 2.90414e-05 4.803150 21.092224????? 1???????? 1
?head(data2,3)
#??????????? Time ChannelA? ChannelB FileNo ChannelNo filtered
#1161 1.83214e-05 4.527559? 6.873434????? 1???????? 1?????? NA
#1171 2.36814e-05 4.881890 13.602919????? 1???????? 1?????? NA
#1181 2.90414e-05 4.803150 21.092224????? 1???????? 1 17.04348
A.K.
----- Original Message -----
From: Ingo Reinhold <ingor at kth.se>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Tuesday, August 27, 2013 9:17 AM
Subject: [R] [plyr] Moving average filter with plyr
Dear all,
I'm stuck with a problem using plyr to process a rather large junk of data.
What I'm trying to do is applying a moving average to all the subparts of
the dataframe (the example data can be found here
https://dl.dropboxusercontent.com/u/2414056/testData.Rdata).
require(plyr)
load("testData.Rdata")
applyfilter<-function(x){
? return(filter(x,rep(1/5, times=5)))
}
data.trash<-ddply(data, .(FileNo, ChannelNo), transform,
filtered=applyfilter(ChannelB))
The result from this is
Error in attributes(output[[var]]) <- attributes(value) : invalid time series
parameters specified
though the number of return values seems right to me.
Do you have any thoughts or suggestions?
Many thanks,
Ingo
??? [[alternative HTML version deleted]]
______________________________________________
R-help at 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.