Hello Jim,this is my script now; I am having this error when I called the function;" In mean.default(list(era...1. = 1:444, Node_freq = c(-0.389855332400718, : argument is not numeric or logical: returning NA" Any help will be much appreciated.
Kwesi rm(list = ls()) setwd('/home/kwesi/Documents/700hpa/soms/') # Reading the data era <- read.csv(file="som_freq.csv",header = TRUE, sep = ",",dec = ".") era.scaled <- scale(era[,2:3], center = TRUE, scale = TRUE) era.sta<-data.frame(era[,1],era.scaled) era.sta collapse_values<-function(x,span,FUN="mean",na.rm=FALSE) { jump<-span-1 newx<-rep(NA,length(x)-jump) for(i in 1:length(newx)) newx[i]<-do.call(FUN,list(x[i:(i+jump)],na.rm=na.rm)) return(newx) } #test<-1:12 names(era.sta)<-month.abb collapse_values(era.sta,3) era.sta On Mon, Jan 30, 2017 at 11:53 PM, Jim Lemon <drjimle...@gmail.com> wrote: > Hi Kwesi, > Even without the data, it seems clear that you want something like a > rolling mean. Here is a simple function that will apply a function > like "mean" to successive bits of a vector of numbers: > > collapse_values<-function(x,span,FUN="mean",na.rm=FALSE) { > jump<-span-1 > newx<-rep(NA,length(x)-jump) > for(i in 1:length(newx)) > newx[i]<-do.call(FUN,list(x[i:(i+jump)],na.rm=na.rm)) > return(newx) > } > > test<-1:12 > names(test)<-month.abb > test > collapse_values(test,3) > [1] 2 3 4 5 6 7 8 9 10 11 > > Jim > > > > On Mon, Jan 30, 2017 at 11:53 PM, Kwesi Quagraine > <starskykw...@gmail.com> wrote: > > Hello, I have a data with two variables nodes and index, I want to > extract > > 3 months seasons, with a shift of 1 month, that is, DJF, JFM, FMA etc to > > OND. Was wondering how to go about it. Kindly find attached the data as > csv. > > Any help will be appreciated. > > > > Regards, > > Kwesi > > > > -- > > Try not to become a man of success but rather a man of value-Albert > Einstein > > > > University of Cape Coast|College of Agriculture and Natural > Sciences|Department > > of Physics| > > Team Leader|Recycle Up! Ghana|Technology Without Borders| > > Other emails: kwesi.quagra...@ucc.edu.gh|kwesi.quagra...@teog.de| > > Mobile: +233266173582 > > Skype: quagraine_cwasi > > Twitter: @Pkdilly > > ______________________________________________ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > -- Try not to become a man of success but rather a man of value-Albert Einstein University of Cape Coast|College of Agriculture and Natural Sciences|Department of Physics| Team Leader|Recycle Up! Ghana|Technology Without Borders| Other emails: kwesi.quagra...@ucc.edu.gh|kwesi.quagra...@teog.de| Mobile: +233266173582 Skype: quagraine_cwasi Twitter: @Pkdilly [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.