Read an Excel file directly from a R script

后端 未结 12 936
误落风尘
误落风尘 2020-11-22 13:52

How can I read an Excel file directly into R? Or should I first export the data to a text- or CSV file and import that file into R?

12条回答
  •  广开言路
    2020-11-22 14:38

    library(RODBC)
    file.name <- "file.xls"
    sheet.name <- "Sheet Name"
    
    ## Connect to Excel File Pull and Format Data
    excel.connect <- odbcConnectExcel(file.name)
    dat <- sqlFetch(excel.connect, sheet.name, na.strings=c("","-"))
    odbcClose(excel.connect)
    

    Personally, I like RODBC and can recommend it.

提交回复
热议问题