Maddy
Maddy

Reputation: 363

Making .RData file from Excel sheet

How can I save data from an Excel sheet to .RData file in R? I want to use one of the packages in R and to load my dataset as data(dataset) i think i have to save the data as .RData file and then load that into the package. My data currently is in an Excel spreadsheet.

my excel sheets has column names like x, y , time.lag. I have saved it as .csv then i use: x=read.csv('filepath', header=T,) then i say data(x) and it shows dataset 'x' not found

Upvotes: 1

Views: 12399

Answers (3)

John
John

Reputation: 43329

save your Excel data as a .csv file and import it using read.csv() or read.table(). Help on each will explain the options.

For example, you have a file called myFile.xls, save it as myFile.csv.

library(BBMM)

# load an example dataset from BBMM
data(locations)


# from the BBMM help file
BBMM <- brownian.bridge(x=locations$x, y=locations$y, time.lag=locations$time.lag[-1], location.error=20,  cell.size=50)
bbmm.summary(BBMM)

# output of summary(BBMM)
Brownian motion variance :  3003.392
Size of grid :  138552 cells
Grid cell size :  50


# subsitute locations for myData for your dataset that you have read form a myFile.csv file
myData <- read.csv(file='myFile.csv', header=TRUE)

head(myData) # will show the first 5 entries in you imported data

# use whatever you need from the BBMM package now ....

Upvotes: 5

mlt
mlt

Reputation: 1669

Check RODBC package. You can find an example in R Data Import/Export. You can query data from excel sheet as if from a database table.

The benefit of reading Excel sheet with RODBC is that you get dates (if you work with any) in a proper format. With intermediate CSV, you'd need to specify a column type, unless you want it to be a factor or string. Also you can query only a portion of your data if you need so thus making subset() unnecessary.

Upvotes: 4

Chase
Chase

Reputation: 69251

There are also several packages that allow directly reading from XLS and XLSX files. We've even had a question on that topic here and here for example. However you decide to read in the data, saving into an RData can be handled with save, save.image, saveRDS and probably some others I'm not thinking about.

Upvotes: 6

Related Questions