Friday, March 18, 2011

Importing Excel data into R

First save Excel into text file (see earlier post).
EX: I created a 2x2 table with no headers and saved it to E drive (dat path E:\Table2forR.txt)

In R, check working directory
> getwd()

If it's not correct (in this case, not set to E drive), reset it:
> setwd("E:")

Set R to read your table and rename it (renamed from "Table2forR" to "mydata" here)
> mydata = read.table("Table2forR.txt")

Check it:
> mydata

Should get output:
V1 V2
1 336 355
2 955 947

No comments:

Post a Comment