Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Conditional replacing of values ina a variable based on valuse in multiple other variables in R

$
0
0

I have a following line of code which replaces a value in a variable (var2) based on a value in other variable (var1)

df$var2[df$var1 > 0] <- NA

However I would like to extend this and replace variables (e.g var5) in the data frame based on values in multiple other variables (var1, var2, var3, var4) which are coded in specific columns 13:16.

I tried

df$var5[df[c(13:16)] > 0] <- NA

which would not work correctly and I would like to know why and how to optimally amend the code.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>