Skip to content
Prev 391557 / 398498 Next

R-help Digest, Vol 231, Issue 9

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 at r-project.org wrote: