I am trying to name the columns of a dataframe, but the dataframe is chosen dynamically. Any idea why this does not work? Below is an example, but in my real case I get a different error. As of now I would just like to know what causes either of the errors, Thanks :
Error in file(filename, "r") : caot open the coection In addition: Waing message: In file(filename, "r") : caot open file 'df': No such file or directory
#ASSIGN data frame name dynamically
> assign(as.character("df"), data.frame(c(1:10), c(11:20)))
>
#IT WOrked
> df
c.1.10. c.11.20.
1 1 11
2 2 12
3 3 13
4 4 14
5 5 15
6 6 16
7 7 17
8 8 18
9 9 19
10 10 20
>
#Call the data frame dynamically, it works
> eval(parse(text = c("df")))
c.1.10. c.11.20.
1 1 11
2 2 12
3 3 13
4 4 14
5 5 15
6 6 16
7 7 17
8 8 18
9 9 19
10 10 20
>
#name the columns
> colnames(df) <- c("a", "b")
> df
a b
1 1 11
2 2 12
3 3 13
4 4 14
5 5 15
6 6 16
7 7 17
8 8 18
9 9 19
10 10 20
>
#name columns of dynamically chosen data frame, retus and error
> colnames(eval(parse(text = c("df")))) <- c("c", "d")
Error in colnames(eval(parse(text = c("df")))) <- c("c", "d") :
target of assignment expands to non-language object
