'How can I have R skip over one segment embedded in a wider line of code?
How can I have R skip over one segment embedded in a wider line of code? In the code below, I would like for R to compute the operations for var1 and var3.
df <- df %>%
mutate(newvar= df$var1 + df$var2 + df$var3)
To note: I get I could use # to have R ignore all the line, but I just want it to ignore + df$var2
Thank you,
Solution 1:[1]
Format the line differently and commenting works:
df <- df %>%
mutate(newvar=
df$var1
+ df$var2
+ df$var3
)
Now you can comment out any of the parts, e.g.
df <- df %>%
mutate(newvar=
df$var1
# + df$var2
+ df$var3
)
Normally it's a bad idea to put operators at the start of a line instead of the end because R might think the previous line ends the whole statement, but in this the parens around the whole thing mean that's not an issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user2554330 |
