Replace Negative Values by Zero in R (2 Examples) | Exchange, Substitute & Set to 0 | Vector & Data

preview_player
Показать описание
R code of this video:

vec <- c(-1, 4, 2, 5, -3, 9, -9, 0, 5) # Create example vector
vec # Print example vector

vec_positive <- vec # Duplicate vector
vec_positive[vec_positive < 0] <- 0 # Set negative values to 0
vec_positive # Print updated vector

x2 = -1,
x3 = -2:5)

data_positive <- data # Duplicate data frame
data_positive[data_positive < 0] <- 0 # Set negative values to 0

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

hello again, was away for some time, now have to cover i think 15 videos all at once. Please keep up the good work

razorscythe
Автор

how to replace negative values with zero for specific columns (eg. two columns)? I am able to do for one column or for whole data frame but not for specific columns. thanks

sangaydorji