In R, I have come across an example in which both =
and <-
are valid for assignment. e.g.
> y = c("hello", "world")
> y
[1] "hello" "world"
> y2 <- c("hello", "world")
> y2
[1] "hello" "world"
I have also come across an example in which =
is invalid and <-
is valid. e.g.
> quote(y[1] <- 1)
y[1] <- 1
> quote(x[1] = 1)
Error: unexpected '=' in "quote(x[1] ="
My question is, are there any cases in which the vice versa is true? i.e. <-
is invalid whilst =
is valid?
Reason for asking this question is to understand whether to stick with =
, <-
, or either (depending on circumstances) when performing assignment operation in R.
This will really help me setting up my mindset when performing coding in R.
Thank you!