I am a beginner and have recently started using R instead of Stata because of its open-source nature.
I am a little confused about "+" continue symbol.
Here's how my data looks like:
head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
Let's consider four scenarios:
Scenario 1: I have noticed that RStudio automatically appends "+" if I write the following block of code:
attach(mtcars)
cyl.f <- factor(cyl, levels= c(4,6,8),
labels = c("4 cylinder", "6 cylinder",
"8 cylinder"))
gets changed to :
cyl.f <- factor(cyl, levels= c(4,6,8),
+ labels = c("4 cylinder", "6 cylinder",
+ "8 cylinder"))
As you can see above, RStudio automatically appended "+"
Scenario 2: If I add "+" at the end of the code, it doesn't work for some strange reasons:
cyl.f <- factor(cyl, levels= c(4,6,8), +
labels = c("4 cylinder", "6 cylinder", +
"8 cylinder"))
This throws an error.
Scenario 3: If I add "+" at the beginning of the code, it doesn't work for some strange reasons:
cyl.f <- factor(cyl, levels= c(4,6,8),
+ labels = c("4 cylinder", "6 cylinder",
+ "8 cylinder"))
This throws an error. This is understandable because RStudio automatically adds another "+" continue operator.
Scenario 4:
windows()
ggplot(data=mtcars, aes(x=wt, y=mpg)) +
geom_point() +
labs(title="Automobile Data", x="Weight", y="Miles Per Gallon")
If I don't add "+", this doesn't work. Apparently, it seems "+" is a "piping" operator above.
Now, the challenge is that I can't google this or search on SO because both the search engines think that "+" is an OR operator.
Can someone please explain when "+" is an operator for "continue" and when it is an operator for "piping."
I'd appreciate any thoughts and detailed explanation. This is extremely confusing for me.