Hello, I have a data.frame and I want to transfor it in a list of rows or columns. I can do apply(myDataFrame,MARGIN=1,FUN=???) I remember that there is a function which mean return or access column ... something like "::" or "]," or "[," I can't remember can somebody refresh my memory? -- View this message in context: http://r.789695.n4.nabble.com/access-row-access-col-access-tp4292531p4292531.html Sent from the R help mailing list archive at Nabble.com.
I have to admit, I have very little idea what you are trying to do. Can you provide an example? In general, the i-th column of a data frame can be accessed with mydataframe[, i] but that doesn't help with whatever you want to do with apply(). Sarah On Fri, Jan 13, 2012 at 10:45 AM, statquant2 <statquant at gmail.com> wrote:> Hello, > I have a data.frame and I want to transfor it in a list of rows or columns. > I can do apply(myDataFrame,MARGIN=1,FUN=???) > > I remember that there is a function which mean return or access column ... > something like "::" or "]," or "[," > I can't remember can somebody refresh my memory? >-- Sarah Goslee http://www.functionaldiversity.org
http://cran.r-project.org/doc/manuals/R-intro.pdf --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. statquant2 <statquant at gmail.com> wrote:>Hello, >I have a data.frame and I want to transfor it in a list of rows or >columns. >I can do apply(myDataFrame,MARGIN=1,FUN=???) > >I remember that there is a function which mean return or access column >... >something like "::" or "]," or "[," >I can't remember can somebody refresh my memory? > >-- >View this message in context: >http://r.789695.n4.nabble.com/access-row-access-col-access-tp4292531p4292531.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >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.
On Jan 13, 2012, at 10:45 AM, statquant2 wrote:> Hello, > I have a data.frame and I want to transfor it in a list of rows or > columns. > I can do apply(myDataFrame,MARGIN=1,FUN=???) > > I remember that there is a function which mean return or access > column ... > something like "::" or "]," or "[," > I can't remember can somebody refresh my memory?It is definitely "the long way around) to do this, since [,5] would get the same results, but if you want the fifth element in each row you could do this: > dat id x1 x2 x3 y1 y2 y3 z1 z2 z3 v 1 1 2 4 5 10 20 15 200 150 170 2.5 2 2 3 7 6 25 35 40 300 350 400 4.2 > apply(dat, 1, "[", 5) [1] 10 25 When 'apply' is used, the trailing arguments are matched either by position or name to the arguments of the function. In this case the 5 gets matched to the "i" for the "[" function. Because "[" is primitive the name is actually ignored even if offered, so using any other name would not change the result: > apply(dat, 1, "[", j=5) [1] 10 25 Whereas if you were using quantile as your function, you might perhaps use prob=c(,25,,75), na.rm=TRUE or na.rm=TRUE prob=c(,25,,75), prob=c(, 25,,75) -- David Winsemius, MD West Hartford, CT