I am a complete newby to Rstudio and I am struggling with renaming column names where the column is a number.
I can use ashes_match[,3] to display the column but when I try to rename it I am having difficulties.
The column names are from a combined set of data with the last four being the second data set.
1] "batter" "team" "role" "Innings" "description" "1" "2" "3"
[9] "4"
I am trying to rename column 3 to scored without success. I have used the following:
rename(ashes_match, "scored" = "[,3]")
this is the error message
Error in UseMethod("rename") :
no applicable method for 'rename' applied to an object of class "c('matrix', 'array', 'character')"
Just to give you a little background as to why, you have to surround column names that are not “syntactically valid” in R in backticks.
From the documentation for the base R function, make.names():
A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number.
Any of R's reserved words are also non-syntactic names (i.e. to use them, you'll need to surround them in backticks).