I would like to winsorize my data. As data is longitudinal (see below for an example) I have to winsorize by ID. Data collection was finished when the value 100 was reached. (Below is just an example, not my real data set. I have few (1-3) outliners that reached value 100 at for example scale= 20 when the majority of people reached 100 at scale =5. Therefore, I would like to 'clean' my data.
ID scale value
CAR 1 0
CAR 2 50
CAR 3 70
CAR 4 100
RIDE 1 0
RIDE 2 0
RIDE 3 1
RIDE 4 10
RIDE 5 30
RIDE 5 40
RIDE 6 80
RIDE 7 100
BUS 1 25
BUS 2 60
BUS 3 80
BUS 4 90
BUS 5 100
I've tried
library(psych)
winsor(data$value, trim = 0.05, na.rm=TRUE, by="ID")
but it won't work. Any ideas?