[R] Excel export into R

Alberto Monteiro albmont at centroin.com.br
Thu Mar 6 12:37:16 CET 2008


Keizer_71 wrote:
> 
> I have this in excel
> 
> Control
> 543_BU
> 123_AT
> 432_CU
> 
> I want to be able to import to R so that it will read like this
> 
> c<-c("543_BU","123_AT","432_CU")
> 
> output:
> [1] "543_BU" "123_AT" "432_CU"
> 
> This is just a short version. I have about 200000 rows and i need a simpler
> way instead of typing each one.
> 
It would be nice if you could give a reproducible example, like
giving the xls spreadshit as a xml file, so that it makes it easy
to reproduce the example.

For example, I had some trouble with read.xls, but I could figure 
out (by rtfming) what the problem was. But if I hadn't solved
the problem, I would have asked here, by composing a reproducible
example. The unsent message would have been like this:

--- begin of fictional message ---
Hello, I have a problem with read.xls.

Take this xml file, convert to test.xls (using Excel) and read in R
using x <- read.xls("test.xls")

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <Worksheet ss:Name="Plan1">
  <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="3" x:FullColumns="1"
   x:FullRows="1">
   <Row>
    <Cell><Data ss:Type="String">roman</Data></Cell>
    <Cell><Data ss:Type="String">greek</Data></Cell>
    <Cell><Data ss:Type="String">height</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Marte</Data></Cell>
    <Cell><Data ss:Type="String">Ares</Data></Cell>
    <Cell><Data ss:Type="Number">1.9</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Venus</Data></Cell>
    <Cell><Data ss:Type="String">Aphrodite</Data></Cell>
    <Cell><Data ss:Type="Number">1.6</Data></Cell>
   </Row>
  </Table>
 </Worksheet>
</Workbook>

I want to have a list of the planet names in roman, but
x[,1] is not an array of strings, and cat(x[,1]) gives an error.
--- end of fictional message ---

FWIW, the reply to this message is:
y <- as.matrix(x)
cat(y[,1])

Alberto Monteiro



More information about the R-help mailing list