For a dataframe in the below format:
Name Surename A B C D E F G H I J K L
John Rose 2 3 4 5 3 4 5 6 80 3 3 0
Smith Red 4 5 2 4 5 5 2 4 4 0 3 56
Karl Joe 2 33 4 44 3 4 0 6 80 3 2 5
How can I apply laaply to run the below code for each row(column A:L), and add the in a new column at the end of each row as "New".
H <- 3 * IQR(x, na.rm = T)
out1 <- round(median(x) - H)
out2 <- round(median(x) + H)
x[x < out1] <- out1
x[x > out2] <- out2
x$`New` <- round(mean(x)))
So the expected output would be as below:
Name Surename A B C D E F G H I A B C New
John Rose 2 3 4 5 3 4 5 6 80 3 3 0 4.4
Smith Red 4 5 2 4 5 5 2 4 4 0 3 56 4.3
Karl Joe 2 33 4 44 3 4 0 6 80 3 2 5 14.5
See Question&Answers more detail:os