[R] How to "vectorize" subsetting

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Aug 14 17:23:39 CEST 2013


If your efforts on those unspecified other forums were like this one, perhaps repeating what doesn't work is your problem. You don't appear to have read and understood the footer of any email on this list. For one thing, you need to post in plain text (to avoid the corruption that HTML email can cause). For another, your example is a valiant first attempt, but it is also a good example of why the footer says to provide a reproducible example... "do something" leaves too many possible solutions swimming in my head. A "dput" of before-and-after data frames can aid our understanding, as can a simplified calculation example go one car. Try reading http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example.

Also, this is an email list... you can expect some responses to take hours or days, so it is more polite to check the archives after an hour or two to see if your email was broadcast rather than sending it twice.
---------------------------------------------------------------------------
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.

"Derickson, Ryan, VHACIN" <Ryan.Derickson at va.gov> wrote:
>I'm not trying to repost or spam everyone- I submitted this once before
>I subscribed so I just wanted to resend in case it didn't get
>disseminated. 
>
> 
>
> 
>
>Hello all, 
>
> 
>
>I've tried to solve this for weeks and posted to other forums with
>little success- I'd appreciate any help from anyone. 
>
> 
>
>I have survey data grouped by facility and area (area is a collection
>of
>facilities). Questions are q1-q10. 
>
> 
>
>For each facility, I need to subset each item into the facility's
>responses, and the facility's area responses excluding the facility.
>This might illustrate it better:
>
> 
>
>Area    Facility          Q1... Q10
>
>1        1                  2
>
>1        2                  3
>
>1        3                  1
>
>2        4                  4
>
>2        5                  5
>
>2        6                  2
>
> 
>
>A<- Select Q1 for all Area=1 and Facility!=1; B<- Select Q1 for all
>Facility=1; <do something with A and B>
>
>A<- Select Q1 for all Area=1 and Facility!=2; B<- Select Q1 for all
>Facility=2; <do something with A and B>
>
>A<- Select Q1 for all Area=1 and Facility!=3; B<- Select Q1 for all
>Facility=3; <do something with A and B>                   
>
>...
>
>A<- Select Q10 for all Area=2 and Facility!=6; B<- Select Q10 for all
>Facility=6; <do something with A and B>          
>
> 
>
>I know how to write the code to manually pull each subset, but I have a
>lot of facilities and areas that get renamed from year to year so I
>need
>to "vectorize" my code so each subset doesn't have to be explicitly
>called by area or facility name.
>
> 
>
>Again, I would be incredibly appreciative of any help. I'm at a
>dead-end. 
>
> 
>
> 
>
>Ryan 
>
> 
>
>
>	[[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.



More information about the R-help mailing list