In the course of slicing-and-dicing some data, I had occasion to create a list 
like this:

list(
    subset(my_dataframe, GR1=="XX1"),
    subset(my_dataframe, GR1=="XX2"),
    subset(my_dataframe, GR1=="YY"),
    subset(my_dataframe, GR1 %in% c("XX1", "XX2")), 
    subset(my_dataframe, GR2=="Remission"),
    subset(my_dataframe, GR2=="Relapse"))

I used %in% only once, because there was only one "compound value" (XX1 or XX2) 
for subsetting. But then it occurred to me to use %in% everywhere, taking 
advantage of the fact that a scalar value is the same as a length-1 vector:

list(
    subset(my_dataframe, GR1 %in% "XX1"),
    subset(my_dataframe, GR1 %in% "XX2"),
    subset(my_dataframe, GR1 %in% "YY"),
    subset(my_dataframe, GR1 %in% c("XX1", "XX2")),
    subset(my_dataframe, GR2 %in% "Remission"),
    subset(my_dataframe, GR2 %in% "Relapse"))

It works just fine.  Are there any problems with this style, from the 
standpoints of correctness, aesthetics, etc.?

-John

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to