How can I extract the samples (S1-S5) containing a TRUE value in their row? Solution should apply to a much bigger data frame.> aSamples A B C D . . . 1 S1 FALSE FALSE FALSE FALSE 2 S2 FALSE FALSE NA TRUE 3 S3 FALSE FALSE FALSE FALSE 4 S4 FALSE TRUE FALSE FALSE 5 S5 FALSE FALSE FALSE FALSE . . . Thank you guys, I appreciate your help a lot! [[alternative HTML version deleted]]
On 08/10/2010 09:04 PM, Alexander Eggel wrote:> How can I extract the samples (S1-S5) containing a TRUE value in their row? > Solution should apply to a much bigger data frame. > >> a > Samples A B C D . . . > 1 S1 FALSE FALSE FALSE FALSE > 2 S2 FALSE FALSE NA TRUE > 3 S3 FALSE FALSE FALSE FALSE > 4 S4 FALSE TRUE FALSE FALSE > 5 S5 FALSE FALSE FALSE FALSE > .Please give us *reproducible* examples as the posting guide requests. See ?rowSums
On Aug 10, 2010, at 10:16 PM, Erik Iverson wrote:> On 08/10/2010 09:04 PM, Alexander Eggel wrote: >> How can I extract the samples (S1-S5) containing a TRUE value in >> their row? >> Solution should apply to a much bigger data frame. >> >>> a >> Samples A B C D . . . >> 1 S1 FALSE FALSE FALSE FALSE >> 2 S2 FALSE FALSE NA TRUE >> 3 S3 FALSE FALSE FALSE FALSE >> 4 S4 FALSE TRUE FALSE FALSE >> 5 S5 FALSE FALSE FALSE FALSE >> . > > Please give us *reproducible* examples as the posting guide requests. > > See ?rowSumsOr ?any ?apply>David Winsemius, MD West Hartford, CT
> with(a, Samples[apply(a[,-1], 1, any)])[1] S2 S4 Levels: S1 S2 S3 S4 S5 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alexander Eggel Sent: Wednesday, 11 August 2010 12:05 PM To: r-help at r-project.org Subject: [R] TRUE FALSE issue How can I extract the samples (S1-S5) containing a TRUE value in their row? Solution should apply to a much bigger data frame.> aSamples A B C D . . . 1 S1 FALSE FALSE FALSE FALSE 2 S2 FALSE FALSE NA TRUE 3 S3 FALSE FALSE FALSE FALSE 4 S4 FALSE TRUE FALSE FALSE 5 S5 FALSE FALSE FALSE FALSE . . . Thank you guys, I appreciate your help a lot! [[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.
For huge cases this might be a whiff faster> with(a, Samples[rowSums(a[, -1], na.rm = TRUE) > 0])[1] S2 S4 Levels: S1 S2 S3 S4 S5 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Bill.Venables at csiro.au Sent: Wednesday, 11 August 2010 12:21 PM To: eggali at gmx.net; r-help at r-project.org Subject: [ExternalEmail] Re: [R] TRUE FALSE issue> with(a, Samples[apply(a[,-1], 1, any)])[1] S2 S4 Levels: S1 S2 S3 S4 S5 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alexander Eggel Sent: Wednesday, 11 August 2010 12:05 PM To: r-help at r-project.org Subject: [R] TRUE FALSE issue How can I extract the samples (S1-S5) containing a TRUE value in their row? Solution should apply to a much bigger data frame.> aSamples A B C D . . . 1 S1 FALSE FALSE FALSE FALSE 2 S2 FALSE FALSE NA TRUE 3 S3 FALSE FALSE FALSE FALSE 4 S4 FALSE TRUE FALSE FALSE 5 S5 FALSE FALSE FALSE FALSE . . . Thank you guys, I appreciate your help a lot! [[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. ______________________________________________ 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.
Seemingly Similar Threads
- Extract values from data frame in R
- Identification of Outliners and Extraction of Samples
- [PATCH] Optimize silk_warped_autocorrelation_FIX() for ARM NEON
- [PATCH] Optimize silk_warped_autocorrelation_FIX() for ARM NEON
- [PATCH] Optimize silk_warped_autocorrelation_FIX() for ARM NEON