[R] Filtering an Entire Dataset based on Several Conditions

Achim Zeileis Ach|m@Ze||e|@ @end|ng |rom u|bk@@c@@t
Mon May 9 10:57:59 CEST 2022



On Mon, 9 May 2022, Eric Berger wrote:

> Hi Paul,
> Not completely clear what you are looking for.
> Please create a 3 x 3 example data frame with dummy data and show what you
> want the result to be.

Maybe something like this?

## scaled data frame
z <- scale(cars)

## all z scores < -1.6 or > 1.6
i <- apply(z < -1.6 | z > 1.6, 1, all)
## with 3 instead of 1.6 no observations would fulfill the condition

## select subset
z[i, ]
##         speed     dist
## [1,] 1.626433 1.902258
## [2,] 1.626433 1.941064
## [3,] 1.626433 2.988819
## [4,] 1.815553 1.630618


> On Mon, May 9, 2022 at 11:24 AM Paul Bernal <paulbernal07 using gmail.com> wrote:
>
>> Dear friends,
>>
>> I have a dataframe which every single (i,j) entry (i standing for ith row,
>> j for jth column) has been normalized (converted to z-scores).
>>
>> Now I want to filter or subset the dataframe so that I only end up with a a
>> dataframe containing only entries greater than -3 or less than 3.
>>
>> How could I accomplish this?
>>
>> Best,
>> Paul
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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