[R] Selection with changing number of columns
Peter Alspach
Peter.Alspach at plantandfood.co.nz
Tue Jul 6 22:57:21 CEST 2010
Tena koe Andreas
Assuming you mean
d[d$Var.1==9 | d$Var.2==9 | d$Var.3==9 ,]
not
d[d$Var.1==9 | d$Var.1==9 | d$Var.1==9 ,]
then
d[apply(d, 1, function(x) any(x==9)),]
is one way.
HTH ....
Peter Alspach
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Kunzler, Andreas
> Sent: Tuesday, 6 July 2010 8:34 p.m.
> To: r-help at r-project.org
> Subject: [R] Selection with changing number of columns
>
> Dear list,
>
> I'm looking for a way to select rows of a data.frame with changing
> number of columns (constraint) involved.
>
> Assume a data (d) structure like
>
>
> Var.1 Var.2 Var.3
> 9 2 1
> 2 9 5
> 1 2 1
>
> I know the number of involved columns.
>
> Is there a way to generate the following selection automatically (maybe
> for loop), so that it makes no difference if there are two or ten
> columns involved.
>
> Selection:
> d[d$Var.1==9 | d$Var.1==9 | d$Var.1==9 ,]>
>
> Does anybody know a way?
>
> Thanks
>
> Mit freundlichen Grüßen
>
> Andreas Kunzler
> ____________________________
> Bundeszahnärztekammer (BZÄK)
> Chausseestraße 13
> 10115 Berlin
>
> Tel.: 030 40005-113
> Fax: 030 40005-119
>
> E-Mail: a.kunzler at bzaek.de
>
> ______________________________________________
> 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