I have the following csv file:
name,x,y,z
category,delta,gamma,epsilon
a,1,2,3
b,4,5,6
c,7,8,9
I'd like to create a numeric matrix of just the numbers in this csv dataset.
I've tried the following program:
sample.data - read.csv(sample.csv)
numerical.data - as.matrix(sample.data[-1,-1])
?as.numeric
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
On Wed, 2007-05-16 at 08:10 -0400, Andrew Yee wrote:
I have the following csv file:
name,x,y,z
category,delta,gamma,epsilon
a,1,2,3
b,4,5,6
c,7,8,9
I'd like to create a numeric matrix of just the numbers in this csv dataset.
I've tried the following program:
sample.data -
have a look at: ?as.numeric() and ?data.matrix().
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web:
Thanks for the suggestion and the explanation for why I was running into
these troubles.
I've tried:
as.numeric(as.matrix(sample.data[-1, -1]))
However, this creates another vector rather than a matrix. Is there a
straight forward way to convert this directly into a numeric matrix rather
than
On Wed, 2007-05-16 at 08:40 -0400, Andrew Yee wrote:
Thanks for the suggestion and the explanation for why I was running
into these troubles.
I've tried:
as.numeric(as.matrix(sample.data[-1, -1]))
However, this creates another vector rather than a matrix.
Right. That's because I'm an
Thanks for the suggestion.
However, I've tried sapply and data.matrix.
The problem is that it while it returns a numeric matrix, it gives back:
1 1 1
2 2 2
3 3 3
instead of
1 2 3
4 5 6
7 8 9
The latter matrix is the desired result
Thanks,
Andrew
On 5/16/07, Marc Schwartz [EMAIL PROTECTED]
Thanks again to everyone for all your help.
I think I've figured out the solution to my dilemma. Instead of using
data.matrix or sapply, this works for me:
sample.data-read.csv(sample.csv)
sample.matrix.raw-as.matrix(sample.data[-1,-1])
sample.matrix - matrix(as.numeric(sample.matrix.raw),
On Wed, 2007-05-16 at 09:05 -0400, Andrew Yee wrote:
Thanks for the suggestion.
However, I've tried sapply and data.matrix.
The problem is that it while it returns a numeric matrix, it gives
back:
1 1 1
2 2 2
3 3 3
instead of
1 2 3
4 5 6
7 8 9
The latter matrix is the
I think this might be a bit more straight forward:
R mat - do.call(cbind, scan(clipboard, what=list(NULL, 0, 0, 0),
sep=,, skip=2))
Read 3 records
R mat
[,1] [,2] [,3]
[1,]123
[2,]456
[3,]789
Andy
From: Andrew Yee
Thanks again to everyone for all
On Wed, 2007-05-16 at 11:29 -0400, Liaw, Andy wrote:
I think this might be a bit more straight forward:
R mat - do.call(cbind, scan(clipboard, what=list(NULL, 0, 0, 0),
sep=,, skip=2))
Read 3 records
R mat
[,1] [,2] [,3]
[1,]123
[2,]456
[3,]789
11 matches
Mail list logo