PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, December 19, 2022

[FIXED] How can I have R skip over one segment embedded in a wider line of code?

 December 19, 2022     r, syntax, tidyverse     No comments   

Issue

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

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.



Answered By - user2554330
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing