Hi,
I wanted to ask if there is a way to use the colnmaes() function by providing the name of the column I want? and not by providing the index of the column?
For example I have
z<- data.frame(x=1:10,y=11:20)
> z
x y
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
If I want to replace the name of the first column I'll do:
> z
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
But how can I replace the name if I don't know (or don't want to find out) the index of the column for which I want to set the new name?
For example if I want now to replace the name "
new.name" to "xxx" by providing the name of the column (i.e., "
new.name") and by providing the its index (i.e., z[1]). I tried for example
but I get an error.
Any ideas? I have an idea how to pass it but I was wondering if there is a way to do it using colnames()
Thanks
Ayala