[R] [Newbie] Row-Iterator for data.frame??

Timothy H. Keitt Timothy.Keitt at StonyBrook.Edu
Wed May 9 23:48:37 CEST 2001


Try:

	for(i in 1:nrow(dframe)) my.row <- dframe[i, ]

T.

Till Baumgaertel wrote:

> hello all,
> 
> for my diploma-thesis i want to statitically analyze near-infrared-spectra.
> a spectrum is given by the y-values of 1038 equi-distant x-points.
> in nature, a spectrum is a continuous curve. for analysis, every x-point
> is seen as a statistical variable.
> 
> now my problem:
> first, i read a csv-table in a data.frame called sTable via read.table.
> 
> besides some meta-data there are 1038 variables holding absorbance-values
> for each wave-number, so a spectrum can be seen as a "case". 
> 
> when i calculate e.g. means for every variable, R works very *fast*. also
> if i want to scale a variable for every spectrum (=case) it's fast: sTable$WN4000
> <- sTable$WN4000 / 1.34 .
> but for some reasons i have to iterate through the spectra, especially when
> i want to differentiate a curve, because then i first have to build a interpolation
> polynom from the given x-points and y-values of a specific case.
> 
> i wrote a function getCase <- function( dataFrame, caseNo) with return-value
> of type data.frame and holding the case "caseNo" of the dataFrame. 
> 
> now, this results in absolutely bad performance. 
> 
> my question: 
> what is the most convenient and fastest way to access a single row of a
> data.frame? if possible, i'd like something i could use like this:
> sTable <- getSpectraTable()
> case11 <- getRow( sTable, 11)
> wn4000 <- case11$WN4000
> is there a built-in function/method in R i didn't find yet?
> also i'd like to avoid casting the data.frame to a matrix (or whatever)
> for reducing the risks by holding data redundantly.
> 
> thank you for your help!
> till
> 
> 
> 
> 
> 
> ________________________________________
> Der clevere Infobote - Shopping-Tipps bequem abonniert. Jetzt neu bei http://www.epost.de
> 
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 


-- 
Timothy H. Keitt
Department of Ecology and Evolution
State University of New York at Stony Brook
Phone: 631-632-1101, FAX: 631-632-7626
http://life.bio.sunysb.edu/ee/keitt/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list