read xlsx in r code example
Example 1: read xlsx in r
require(xlsx)
read.xlsx("myfile.xlsx", sheetName = "Sheet1")
read.xlsx2("myfile.xlsx", sheetName = "Sheet1")
Example 2: read xlsx in r
require(gdata)
df = read.xls ("myfile.xlsx"), sheet = 1, header = TRUE)
Example 3: read xlsx in r
require(RODBC)
conn = odbcConnectExcel("myfile.xlsx")
sqlTables(conn)$TABLE_NAME
df = sqlFetch(conn, "Sheet1")
df = sqlQuery(conn, "select * from [Sheet1 $]")
close(conn)
Example 4: read xlsx in r
require(xlsx)
coln = function(x) {
y = rbind(seq(1, ncol(x)))
colnames(y) = colnames(x)
rownames(y) = "col.number"
return(y)
}
data = read.xlsx2("myfile.xlsx", 1)
coln(data)
x = 3
data = read.xlsx2("myfile.xlsx", 1,
colClasses = c(rep("character", x), rep("numeric", ncol(data)-x+1))
)
Example 5: open xlsx with r
my_data <- read.table(file = "clipboard",
sep = "\t", header=TRUE)