3
Let’s say I have a 6x5 data.frame, for example:
print(Dados)
Linha A B C D E
L1 4 3 -1 2 4
L2 1 -2 1 -5 1
L3 -1 -1 2 3 4
L4 2 4 5 -7 9
But I want to replace the Negative values of the data.frame with Zeros, for example:
Linha A B C D E
L1 4 3 0 2 4
L2 1 0 1 0 1
L3 0 0 2 3 4
L4 2 4 5 0 9
How can I replace variables with NEGATIVE values by ZERO within my date frame.?
Dice.
Dados <- read.table(text = "
Linha A B C D E
L1 4 3 -1 2 4
L2 1 -2 1 -5 1
L3 -1 -1 2 3 4
L4 2 4 5 -7 9
", header = TRUE)
Why close? This question is about programming and may even have answers only in R base or with the package
dplyr
.– Rui Barradas
If you don’t care about Warning the simplest way q exists is
Dados[Dados<0] <- 0
it will replace anything negative with0
will happen a Warning pq yourdata.frame
not all in numbers, strings in the middle ...– ederwander
Thanks for the support @Rui Barradas
– Izak Mandrak