When specifying named arguments, you have to use =, instead of <-.
This code
data.frame(x2 <- x2, y2 <- y2)is actually iterpreted like this:
data.frame( `x2 <- x2` = (x2 <- x2), `y2 <- y2` = (y2 <- y2) )x2 <- x2 and y2 <- y2 are column name. As you know, whitespaces and symbols are converted to ..
therefore you will get x2....x2 and y2....y2 as column names.
(For (x2 <- x2) and (y2 <- y2), they return x2 and y2, their assignee values.
So, the returned data.frame has no columns named x2 or y2.
> f <- function(){
+ x2 <- 1:10
+ y2 <- x2^2
+ df <- data.frame(x2 <- x2, y2 <- y2)
+ df
+ }
> f()
x2....x2 y2....y2
1 1 1
2 2 4
3 3 9
4 4 16
5 5 25
6 6 36
7 7 49
8 8 64
9 9 81
10 10 100Don't worry. You can use =. Perfect.
data.frame(x2 = x2, y2 = y2)Sorry for my poor English…\(ツ)/