[R] R-help Digest, Vol 231, Issue 9
Pedro Paulo Chrispim
pedrop@u|o@chr|@p|m @end|ng |rom gm@||@com
Mon May 9 13:20:37 CEST 2022
Hi, Paul.
Not sure if you want to drop only cases out of limits or entire rows
with any case out of limits.
When I face similar tasks to select only cases, I write a function to
select the cases, like:
subset.zscore <- function(x){
ifelse(x > -3 & x < 3, x, NA)
}
and use it to identify the cases. So if I have this dummy object:
a <- seq(from=-5, to=5, by=.01)
b <- seq(from=-6, to=4, by=.01)
df.original <- data.table::data.table(sample(a,100,replace = TRUE),
sample(b,100,replace = TRUE))
I would now subset the cases (not entire rows):
df2 <- df.original[,lapply(.SD,(subset.zscore)]
Note that I use data.table package. You would need to convert your
data.frame object into data.table before to run this code.
I hope this helps you.
Best,
Pedro Paulo.
On 09/05/22 07:00, r-help-request using r-project.org wrote:
> Send R-help mailing list submissions to
> r-help using r-project.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://stat.ethz.ch/mailman/listinfo/r-help
> or, via email, send a message with subject or body 'help' to
> r-help-request using r-project.org
>
> You can reach the person managing the list at
> r-help-owner using r-project.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of R-help digest..."
>
> Today's Topics:
>
> 1. Filtering an Entire Dataset based on Several Conditions
> (Paul Bernal)
> 2. Re: Filtering an Entire Dataset based on Several Conditions
> (Eric Berger)
> 3. Re: Filtering an Entire Dataset based on Several Conditions
> (Achim Zeileis)
> 4. Re: Filtering an Entire Dataset based on Several Conditions
> (Rasmus Liland)
> 5. Re: Filtering an Entire Dataset based on Several Conditions
> (Jim Lemon)
> 6. Re: Filtering an Entire Dataset based on Several Conditions
> (Rui Barradas)
>
> _______________________________________________
> R-help using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help
mailing list