-3

I have an Excel Sheet with 300 Variables (Columns) and 400 Observations (Rows). I want to enter that sheet into R keeping the same setting and I want to keep it as a matrix hopefully to perform the regression analysis after.

2
  • 6
    This could be find in the about the second section of any R introductory text. People here are very nice and willing to help, but with the premise that we do our homework and try to Google first. I am a noob too and let's learn together! :D
    – shirleywu
    Mar 2, 2013 at 8:07
  • 1
    Googling for 'r read excel file' will probably get you your answer, or at least the functions and packages you should use. Mar 2, 2013 at 8:12

3 Answers 3

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

10

Save the Excel file as a comma delimited CSV file, then import in R: read.csv("(path of file)",header=T)

4
  • obviously header=T is only needed if the CSV has an header (usually a good thing)
    – nico
    Mar 2, 2013 at 8:10
  • 3
    @nico, I believe header = TRUE is default for read.csv anyway, since most csv's tend to have a header (unlike read.table, where the default is FALSE). Mar 2, 2013 at 8:31
  • You guys are unbelievable!...X=read.csv(file="RD.csv", header=TRUE) it works with me and I learned the other suggestions you've listed Mar 3, 2013 at 4:15
  • You might want to join the R Public Chat Room :D
    – shirleywu
    Mar 3, 2013 at 4:20
6

There are various ways to read an Excel file into R.

The R manual gives some tips at this regard: http://cran.r-project.org/doc/manuals/R-data.html#Reading-Excel-spreadsheets

For instance you can use the RODBC package or the xlsReadWrite package.

However, I agree with @shirleywu that saving as csv is a better option, and gives a much larger compatibility.

3

If you are new to R and you are having challenges like this you might want to consider working with RStudio (wwww.rstudio.org). RStudio is a front-end user interface for R and it has a neath feature on the right-hand-side, which helps you to upload upload CSV-files so you can use them in your analysis. In the screenshot below you see where the function is located. I assume that you know how to make a CSV file of an Excel document.

enter image description here

2
  • 1
    Thanks man and Yes I am totally new and using RStudio but I don't want to depend on RStudio only, I want to know the command syntax as well :-)....X=read.csv(file="RD.csv", header=TRUE) works with me Mar 3, 2013 at 4:17
  • @AtheerAlAttar: When you use the feature in RStudio you will see the code showing up on the left part of the screen, which allows you to modify it easily. This is often handy as you don't have to retype the path and file names.
    – Jochem
    Mar 3, 2013 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.