1
2require(xlsx)
3read.xlsx("myfile.xlsx", sheetName = "Sheet1")
4read.xlsx2("myfile.xlsx", sheetName = "Sheet1")
5
1
2require(gdata)
3df = read.xls ("myfile.xlsx"), sheet = 1, header = TRUE)
4
1# Loading
2library("readxl")
3# xls files
4my_data <- read_excel("my_file.xls")
5# xlsx files
6my_data <- read_excel("my_file.xlsx")
1
2require(RODBC)
3conn = odbcConnectExcel("myfile.xlsx") # open a connection to the Excel file
4sqlTables(conn)$TABLE_NAME # show all sheets
5df = sqlFetch(conn, "Sheet1") # read a sheet
6df = sqlQuery(conn, "select * from [Sheet1 $]") # read a sheet (alternative SQL sintax)
7close(conn) # close the connection to the file
8
1
2require(xlsx)
3coln = function(x) { # A function to see column numbers
4 y = rbind(seq(1, ncol(x)))
5 colnames(y) = colnames(x)
6 rownames(y) = "col.number"
7 return(y)
8}
9data = read.xlsx2("myfile.xlsx", 1) # open the file
10coln(data) # check the column numbers you want to have as factors
11x = 3 # Say you want columns 1-3 as factors, the rest numeric
12data = read.xlsx2("myfile.xlsx", 1,
13 colClasses = c(rep("character", x), rep("numeric", ncol(data)-x+1))
14)
15