Hi,
I would like to conditionally mutate numeric values across several columns; I have managed to do it and it works, but it looks super clumsy. Is it possible to write this in a nicer way?
Here an extract of the dataset:
I would like to conditionally change the value of all the numerical variables:
If the value is less then 10, I would like it replaced with NA (or ideally leave it blank if possible?)
If the value is more than 33, I would like it replaced with 33,
if the value is between 10and 33 then it should remain the same.
This is what I wrote:
tdata<- rawdata %>%
mutate(T1=ifelse(T1<10, NA, ifelse(T1<33, T1, 33)))%>%
mutate(T2=ifelse(T2<10, NA, ifelse(T2<33, T2, 33)))%>%
mutate(T3=ifelse(T3<10, NA, ifelse(T3<33, T3, 33)))%>%
mutate(C1=ifelse(C1<10, NA, ifelse(C1<33, C1, 33)))%>%
mutate(C2=ifelse(C2<10, NA, ifelse(C2<33, C2, 33)))%>%
mutate(C3=ifelse(C3<10, NA, ifelse(C3<33, C3, 33)))
Any idea how to simplify this?
Cheers