This question already has an answer here:
- Replace negative values by zero 3 answers
Using R, what ifelse, if_else, if, for, or other statements should be used on a data.frame to find the negative numbers and replace them with the positive number 0.001? Said another way, replace all negative numbers in the data.frame with the positive number 0.001. A base R, plyr or dplyr function would work.
set.seed(1)
dfTest <- data.frame(replicate(5, sample(c(-10:99), 7, rep = TRUE)))
In MS-Excel, the code might be =if(x<0, 0.001, x)
. There are several R examples for lists, just not many applicable for data.frames. Thanks.
Aucun commentaire:
Enregistrer un commentaire