Hi From: Alaios [mailto:ala...@yahoo.com] Sent: Wednesday, March 27, 2013 11:46 AM To: PIKAL Petr; R help Subject: Re: [R] Averaging Out many rows from a column AND funtion to string
see inline ________________________________ From: PIKAL Petr <petr.pi...@precheza.cz<mailto:petr.pi...@precheza.cz>> To: Alaios <ala...@yahoo.com<mailto:ala...@yahoo.com>>; R help <R-help@r-project.org<mailto:R-help@r-project.org>> Sent: Wednesday, March 27, 2013 11:24 AM Subject: RE: [R] Averaging Out many rows from a column AND funtion to string Hi > -----Original Message----- > From: r-help-boun...@r-project.org<mailto:r-help-boun...@r-project.org> > [mailto:r-help-bounces@r- > project.org<http://project.org/>] On Behalf Of Alaios > Sent: Wednesday, March 27, 2013 9:13 AM > To: R help > Subject: [R] Averaging Out many rows from a column AND funtion to > string > > Dear all, > 1) I have a very large matrix of > str(keep) > num [1:153899, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ... > that I would like to reduce its size to something like > > str(keep) > num [1:1000, 1:3415] -98.6 -95.8 -96.4 -95.8 -98 ... or anything > similar in size as this is a matrix that needs plotting (so is ok if it > is 1000 row, 995, or 1123) > > I think what I need here is a way of selecting multiple rows and > averaging per column (notice that the column number should stay the > same) Make an index variable and aggregate values according it Something like idx<-cut(1:153899, 153) keep.ag<-aggregate(keep, list(idx), mean) 1) Thanks that returned a data frame.. How I can have a matrix at the end? use as.matrix(data.frame) on numeric part 2) I want to have a string that can be used also for calling a function with the same name. Think of using "mean" to call mean. I need to have R interpret the string in different ways. To call "mean" of what? I am sure I do not understand what is your intention. LogFunction<- function(){} FunctionIndex<- rbind (c(1,"LogFunction"), c(2,"TakeFunction")) print(sprintf('Using the function %s',FunctionIndex[1,1])) This does not contain much clue. Regards Petr PS. Do not use HTML mail messages. Regards Alex > > b. I would like to be able to convert strings that are function names > to real function calls. For example I have something like > > LogFunction<- function(){} > FunctionIndex<- rbind (c(1,"LogFunction"), > c(2,"TakeFunction") > ) > print(sprintf('Using the function %s',FunctionIndex[1,1])) # call the > FunctionIndex[1,1] somehow I am not sure if I understand correctly. Is this what you want? myf <-function(fun="mean", arg) eval(call(fun, arg)) Regards Petr > > > > I would like to thank you in advance for your help > > Regards > Alex > > [[alternative HTML version deleted]] [[alternative HTML version deleted]] ______________________________________________ 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.