[R] Mixed mode import problem

Mark Myatt mark at myatt.demon.co.uk
Thu Aug 9 16:26:11 CEST 2001


Grum, Mikkel <M.GRUM at CGIAR.ORG> writes:
>First question:
>I have an Excel file with both character and numeric variables that I want
>to import to a data.frame, so I've saved the data to a tab-delimited text
>file.
>
>read.table :
>*      Won't identify the mode of my character variables, as some of them
>contain only numbers and none of them are surrounded by quotes,
>*      Won't allow me to specify the mode of my variables,
>*      Doesn't read the whole file, apparently because Excel has added tabs
>beyond the end of some rows.
>
>scan:
>*      Allows me to specify the mode of my variables,
>*      Reads the whole file correctly when I set flush=TRUE,
>*      But gives me a list rather than a data.frame,
>*      And doesn't allow me to specify row.names and col.names
>
>When I use as.data.frame to convert my file to a data.frame, I lose the mode
>of my variables. I tried to protect the mode using I, but if that's the
>correct thing to do, I didn't get the syntax right.
>
>Is there any way the I can define the mode of my variables after I have them
>in my data frame? Or another solution to my problem.

Look at using the scan() functions and specify your variable types in
the 'what' parameter to scan().

>Second question:
>I have a large number of variables, not all of which I'd like to use in all
>the analyses.  How do I select just those that I want for the next analysis?
>
>I've worked through R for beginners, the import/export manual, an
>introduction to R, and considerable chunks of the reference manual, as well
>as a few other texts and I could do with some help.

Use cbind() to bind a set of vectors from the dataset toghether and then
use colnames() to give them names. Use rm() to get rid of the big
dataset.

I hope that helps,

Mark

--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list