[R] conditioning inside an lapply

From: <markleeds_at_verizon.net>
Date: Fri, 11 Apr 2008 16:16:56 -0500 (CDT)


This is probably basic but I want to condition based on the name of the component inside an lapply.

So, in the simple example below, if .elem was x i want to do one thing but if it's y a
different thing etc. Can someone tell me how to do that without using names(temp) as the thing one sends into the lapply ? Thanks.

temp <- list(x=2,y=3,x=4)

invisible(lapply(temp, function(.elem) {

       print(.elem)
     }))

______________________________________________
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. Received on Fri 11 Apr 2008 - 21:21:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 11 Apr 2008 - 21:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive