How do i replace values from a single column of a dataframe. For example all 0 values in column dataz to values of 1
datay dataz
[1,] 0 100
[2,]
This will change values of 5 to NA. You can also use a range.
df <- data.frame(datay = sample(1:5, 10, replace = TRUE), dataz = sample(letters, 10, replace = TRUE))
df$datay[df$datay == 5] <- NA
This will find data smaller than 3 and bigger than 1. Use assign (<-
) to assign your value.
df$datay[df$datay < 3 & df$datay > 1]
Here's a quick example of ifelse
.
ifelse(df$dataz == "w", "oi!", NA)