[R] Recommendation for dealing with mixed input types in CSV

Jason Rupert jasonkrupert at yahoo.com
Thu Oct 29 20:26:48 CET 2009


Currently I have a CSV with mixed input types that I am trying to read in and reformat without having to list off all the column names.  Below is an example of the data:

HouseColor, HouseSize, HouseCost
Blue, 1600, 160e3
Blue, 1600, 160e3

Actually I have about 60 columns like this, so imagine the above repeated about 30 times column-wise.  

Luckily the ones in scientific notation are grouped together, i.e. columns 11-56. 

Using read.csv or as.numeric, is there a way to convert all those in scientific format over to general numeric syntax?  

Right now I have something like the following
input_df<-read.csv(InputFile, skip=0, header=TRUE, strip.white = TRUE)

I tried:
as.numeric(input_df[, 11:56])
but this returns an error 
Error: (list) object cannot be coerced to type 'double'

Oddly it does appear to work successfully row-wiseas.numeric(input_df[1, 11:56]) 
as.numeric(input_df[2, 11:56])
etc.

However, trying it on multiple rows produces the same error as above:
as.numeric(input_df[1:2, 11:56])

After a bit, I became a bit frustrated that this was not working so I tried just deleting the columns:
input_df[1, 11:56]<-NULL

This also failed, so are there any suggestions about how to convert the values in scientific notation over to standard numeric syntaix?

Thank you again again for all your insights and feedback. 







More information about the R-help mailing list