Hi Folks... Œbeen playing with this for a while, with no luck, so I¹m hoping
someone knows it off the top of their head...  Difficult to find this nuance
in the archives, as so many msgs deal with read.csv!

I¹m trying to read a data file with the following structure (a little piece
of the actual data, they are actually csv just didn¹t paste with the
commas):

 wavelength SampleA SampleB SampleC SampleD
 color "green" "black" "black" "green"
 class "Class 1" "Class 2" "Class 2" "Class 1"
 403 1.94E-01 2.14E-01 2.11E-01 1.83E-01
 409 1.92E-01 1.89E-01 2.00E-01 1.82E-01
 415 1.70E-01 1.99E-01 1.94E-01 1.86E-01
 420 1.59E-01 1.91E-01 2.16E-01 1.74E-01
 426 1.50E-01 1.66E-01 1.72E-01 1.58E-01
 432 1.42E-01 1.50E-01 1.62E-01 1.48E-01

Columns after the first one are sample names.  2nd row is the list of colors
to use in later plotting.  3rd row is the class for later manova.  The rest
of it is x data in the first column with y1, y2...following for plotting.

I can read the file w/o the color or class rows with read.csv just fine,
makes a nice data frame with proper data types.  The problem comes when
parsing the 2nd and 3rd rows.  Here¹s the code:

data = read.csv("filename", header=TRUE) # read in data
color = data[1,]; color = data[-1] # capture color info & throw out 1st
value
class = data[2,]; class = class[-1] # capture category info & throw out 1st
value

cleaned.data = data[-1,] # remove color & category info for matrix
operations
cleaned.data = data[-1,]
freq = data[,1] # capture frequency info

What happens is that freq is parsed as factors, and the color and class are
parsed as a data frames of factors.
I need color and class to be characters which I can pass to functions in the
typical way one uses colors and levels.
I need the freq & the cleaned.data info as numeric for plotting.

I don¹t feel I¹m far off from things working, but that¹s where you all come
in!  Seems like an argument of as.something is needed, but the ones I¹ve
tried don¹t work.  Would it help to put color and class above the x,y data
in the file, then clean it off?

Btw, I¹m on a Mac using R 2.6.0.

Thanks in advance, Bryan
*************
Bryan Hanson
Professor of Chemistry & Biochemistry




        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to