[R] Convert matrix to numeric

2011-08-03 Thread Jeffrey Joh
I have a matrix that looks like this: structure(c(0.0376673981759913, 0.111066500741386, 1, 1103, 18, OPEN, DEPR, 0.0404073656092023, 0.115186044704599, 1, 719, 18, OPEN, DEPR, 0.0665342096693433, 0.197570061769498, 1, 1103, 18, OPEN, DEPR, 0.119287147905722, 0.356427096010845, 1, 1103, 18,

Re: [R] Convert matrix to numeric

2011-08-03 Thread Duncan Murdoch
On 03/08/2011 3:04 PM, Jeffrey Joh wrote: I have a matrix that looks like this: structure(c(0.0376673981759913, 0.111066500741386, 1, 1103, 18, OPEN, DEPR, 0.0404073656092023, 0.115186044704599, 1, 719, 18, OPEN, DEPR, 0.0665342096693433, 0.197570061769498, 1, 1103, 18, OPEN, DEPR,

Re: [R] Convert matrix to numeric

2011-08-03 Thread Ken
How about Matrix[1:5,]=as.numeric(Matrix[1:5,]) -Ken Hutchison On Aug 3, 2554 BE, at 3:04 PM, Jeffrey Joh johjeff...@hotmail.com wrote: I have a matrix that looks like this: structure(c(0.0376673981759913, 0.111066500741386, 1, 1103, 18, OPEN, DEPR, 0.0404073656092023,

Re: [R] Convert matrix to numeric

2011-08-03 Thread Sarah Goslee
Hi Jeffrey, On Wed, Aug 3, 2011 at 3:04 PM, Jeffrey Joh johjeff...@hotmail.com wrote: I have a matrix that looks like this: structure(c(0.0376673981759913, 0.111066500741386, 1, 1103, 18, OPEN, DEPR, 0.0404073656092023, 0.115186044704599, 1, 719, 18, OPEN, DEPR, 0.0665342096693433,

Re: [R] Convert matrix to numeric

2011-08-03 Thread Nordlund, Dan (DSHS/RDA)
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ken Sent: Wednesday, August 03, 2011 12:13 PM To: Jeffrey Joh Cc: r-help@r-project.org Subject: Re: [R] Convert matrix to numeric How about Matrix[1:5,]=as.numeric(Matrix[1

Re: [R] Convert matrix to numeric

2011-08-03 Thread David Winsemius
Here's what you _should_ do 1) transpose 2a) as.data.frame 3a) fix the stupid default stringsAsFactor behavior 4a) convert the first 5 columns to numeric dfrm - as.data.frame( t( structure(.) ) ) dfrm[, 1:5] -lapply(dfrm[, 1:5], as.character) dfrm[, 1:5] -lapply(dfrm[, 1:5], as.numeric) Or: