[R] Selecting Variables
Henrique Dallazuanna
wwwhsd at gmail.com
Tue Aug 5 16:05:21 CEST 2008
Try this:
data.frame(ID = x$ID,
Max_Exposure = max(rowSums(x[,-1] == "y")),
Unique_Exposure = rowSums(x[,-1] == "y"))
On Tue, Aug 5, 2008 at 10:21 AM, Michael Pearmain <mpearmain at google.com> wrote:
> Hi All,
>
> i have a dataset that i want to dynamically inspect for the number of
> variables that start with "Exposure_" and then for these count the entries
> across each case i.e
>
> ID Exposure_1 Exposure_2 Exposure_3
> 1 y y y
> 2 y y -
> 3 y - -
>
> So the corresponding new variables that would be created are
>
> ID Max_Exposure Unique_Exposure
> 1 3 3
> 2 3 2
> 3 3 1
>
> I know this may seem fairly basic but it will give me the starting point to
> develop more advanced things with loop and nat lang
>
> Thanks in advance
>
> Mike
>
> [[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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list