Import of tabular data

Import of a tab-delimited tabular file

myDF <- read.delim("myData.xls", sep="\t")

Import of Excel file. Note: working with tab- or comma-delimited files is more flexible and preferred.

library(gdata)
myDF <- read.xls"myData.xls")

Import of Google Sheets. The following example imports a sample Google Sheet from here. Detailed instructions for interacting from R with Google Sheets with the required googlesheets package are here.

library("googlesheets"); library("dplyr"); library(knitr)
gs_auth() # Creates authorizaton token (.httr-oauth) in current directory if not present
sheetid <-"1U-32UcwZP1k3saKeaH1mbvEAOfZRdNHNkWK2GI1rpPM"
gap <- gs_key(sheetid)
mysheet <- gs_read(gap, skip=4)
myDF <- as.data.frame(mysheet)
myDF

Export of tabular data

write.table(myDF, file="myfile.xls", sep="\t", quote=FALSE, col.names=NA)

Line-wise import

myDF <- readLines("myData.txt")

Line-wise export

writeLines(month.name, "myData.txt")

Copy and paste into R

On Windows/Linux systems

read.delim("clipboard") 

On Mac OS X systems

read.delim(pipe("pbpaste")) 

Copy and paste from R

On Windows/Linux systems

write.table(iris, "clipboard", sep="\t", col.names=NA, quote=F) 

On Mac OS X systems

zz <- pipe('pbcopy', 'w')
write.table(iris, zz, sep="\t", col.names=NA, quote=F)
close(zz) 

Homework 3A

Homework 3A: Object Subsetting Routines and Import/Export



Previous page.Previous Page                     Next Page Next page.