[R] How to "vectorize" subsetting

Bert Gunter gunter.berton at gene.com
Wed Aug 14 18:40:15 CEST 2013


mod Jeff Newmiller's comments...

1. Have you read"An Introduction to R? (or other basic tutorial --
there are many on the web). If no, stop posting and do so. This will
help you to understand R's basic data manipulation capabilities and
structures (list, "apply" type functions,...).

2. mod 1), perhaps

?tapply (and friends like ?ave, ?aggregate, ?by)
?split

-- Bert

On Wed, Aug 14, 2013 at 7:03 AM, 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.



-- 

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