[R] What is this called? lapply(datum,"[[","ColumnName")

Bert Gunter gunter.berton at gene.com
Tue Aug 7 23:23:40 CEST 2012


"I... cannot look it up in a book."
Baloney!

Read the R Language Definition manual section on indexing in the
"Evaluation of Expressions" Chapter. Then ?lapply and ?"[[" -- and the
relevant sections in "The Introduction to R" manual.

However, I will admit that it's tricky. The point to grasp --
described at various levels of detail in the above manuals and in
numerous other resources that you can check out on the CRAN website --
is that y[["a"]] is just syntactic sugar for "[["(y,"a")  . R is a
"functional" language (mostly). So your lapply statement is just
lapplying the "[[" function(extraction operator ) to the list of data
frames.

Cheers,
Bert

On Tue, Aug 7, 2012 at 12:06 PM, Kevin Chang <kchang01 at uoguelph.ca> wrote:
> Hello R users
>
>
>
> I recently learned how to use this command:
>
>
> lapply(datum,"[[","ColumnName")
>
>
>
> Unfortunately, I don't know how exactly it works, what it's called (in
> particular the "[[" part], and what other things you can do with it
> (retrieve multiple columns?).
>
>
> Given datum is a list of dataframes with the same column, but different
> number of rows,
>
>
>
> lapply(datum,"[[","ColumnName"),
>
>
>
> Returns you a list of a particular column form each of your dataframes from
> datum.
>
>
>
> I think this is a really useful command, and would like to learn more about
> it.
> Unfortunately I don't know what subject or topic it is under and cannot look
> it up in a book.
>
>
>
> Thank you,
>
>
>
> Kevin
>
>
>
> Master of Science Student
>
> Department of Food, Resource and Agricultural Economics
>
> University of Guelph
> Office:    519-824-4120 ext. 58528
>
> Mobile:  226-979-2813
>
>  <http://fare.uoguelph.ca/users/kchang01>
> http://fare.uoguelph.ca/users/kchang01
>
>
>
>
>
>
>         [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list