I have a problem that is hampering my analyses. For some weird reason, whenever I import a table (csv, text etc) I never get the row numbers to appear in brackets. Instead of this:
>ID Year
[1,] 1 1944
[2,] 1 1945
[3,] 1 1946
I get this:
ID Year
1 1 1944
2 1 1945
3 1 1946
The problem is that R ends up using the first column (1,2,3) as ID and ruins the analysis.
Any ideas?
Thank you!
Your “object printed with row numbers in brackets” is probably a
matrix, while reading from csv you get adata.frame.If you call
as.matrix()on thedata.frameyou get by reading the csv, you will obtain the desired result.e.g. :
A matrix object like this:
yields:
While reading the same data from a csv:
you get:
Converting m2 to a matrix:
you get this: