I have a CSV file that needs to be read into R, transposed (swapping rows for columns) and then processed.
Here is the form of the file (not that columns actually extend to 2014):
Year,1970,1971,1972
Variable one,1,2,3
Variable two,11,22,33
Variable three,111,222,333
When I read it, the years are prefixed with 'X'
> rc <- read.csv("file.csv")
> rc
Year X1970 X1971 X1972
1 Variable one 1 2 3
2 Variable two 11 22 33
3 Variable three 111 222 333
and when I transpose the data everything is treated as a string.
> t(rc)
[,1] [,2] [,3]
Year "Variable one" "Variable two" "Variable three"
X1970 " 1" " 11" "111"
X1971 " 2" " 22" "222"
X1972 " 3" " 33" "333"
If I delete the names for the rows in the csv file, the dates are still prefixed by X but the transpose does not change the data to strings.
So how do I do this properly so that the years are numeric and transposing does not create strings.