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.
-
6This 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– shirleywuMar 2, 2013 at 8:07
-
1Googling for 'r read excel file' will probably get you your answer, or at least the functions and packages you should use.– Paul HiemstraMar 2, 2013 at 8:12
3 Answers
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.
Save the Excel file as a comma delimited CSV file, then import in R: read.csv("(path of file)",header=T)
-
obviously
header=Tis only needed if the CSV has an header (usually a good thing)– nicoMar 2, 2013 at 8:10 -
3@nico, I believe
header = TRUEis default forread.csvanyway, since most csv's tend to have a header (unlikeread.table, where the default isFALSE). 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
-
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.
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.

-
1Thanks 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.– JochemMar 3, 2013 at 15:29