[R] Read data from .csv file as a matrix
shitao at hotmail.com
Wed May 5 22:26:57 CEST 2010
The root of this problem seems to be that you don't fully understand the differences between matrix and data.frame. Read up on them and you'll know how to solve this problem.
temp = read.csv("Weather.csv", sep=",", row.names=1)
temp1 <- as.matrix(temp)
> I have a csv file that contains weather observation (rows) by days (in
> I open using:
>> temp = read.csv("Weather.csv", sep=",")
> and read:
> X X1.Jan X2.Jan X3.Jan X4.Jan
> 1 Min 2 3 4 1
> 2 Max 6 10 8 6
> 3 Forecast Min 3 1 1 3
> 4 Forecast Max 8 7 4 9
> If I type
> I get
> X1.Jan X2.Jan
> 6 10
> The same command on
>> y = matrix(1:21, ncol=7)
>  6.5
> Works because the data is in a matrix. I believe R stores the data from the
> csv file as a data.frame with these annoying headers. So how do I convert
> the data from my csv file into a matrix?
> I tried as.matrix but it did not help.
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
More information about the R-help