The first thing to do before importing data is knowing what directory R is working from. You can see where R will be extracting all data from with the following command:
> getwd() # get current working directory
If you are interested in changing it to where your data is going to be located, that can be changed through:
> setwd("<new path>") # set working directory
TEXT FILES:
The data I've been working with is attached under Weight-BP-Disease-2.txt.
> mydata = read.table("mydata.txt") # read text file
EXCEL FILES:
> install.packages(gdata) #installing
> library(gdata) # load gdata package
> help(read.xls) # documentation
> mydata = read.xls("mydata.xls") # read from first sheet
SPSS FILES:
For SPSS files, you need to save it as portable, or with the .por extension. Afterwards,
library(Hmisc)
mydata <- spss.get("c:/mydata.por", use.value.labels=TRUE)
SAS FILES:
You need to save SAS dataset in trasport format. The following command should work.
libname out xport 'c:/mydata.xpt';
data out.mydata;
set sasuser.mydata;
run;
In R, you run the following commands,
library(Hmisc)
mydata <- sasxport.get("c:/mydata.xpt")