Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How to exclude outliers individually for target & participant in R

$
0
0

I'm (very) new to R, and I was wondering if I could get some help. I'd like to know how to exclude outliers that are two standard deviations for each participant's mean reaction time, and each target's mean reaction time and replace it with na.

My data looks like this:

ptp  rt    group   target
1    1094  E       dog
1    2100  E       hat
2    918   E       dog
2    1211  E       hat
3    1142  E       dog
3    1222  E       hat
1    10    W       dog
1    993   W       hat
2    897   W       dog
2    1078  W       hat
3    4002  W       dog
3    899   W       hat

I've calculated mean and sd for each participant and item

mean <- tapply(data$rt, data$target, mean)
sd <-  tapply(data$rt, data$target, sd)
mean <-  tapply(data$rt, data$ptp, mean)
sd <- tapply(data$rt, data$ptp, sd)

However, I'm super new at R, and working out the code to calculate two standard deviations from the mean (mean+1.96*SD and mean-1.96*SD) and converting all values that are outside of the range for both the participant to NA is a bit beyond me. There must be an easier way than doing this by hand! Any help would be massively appreciated.

Thank you so much, Jen


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>