Wednesday, 7 January 2015

Tips for R



Here are some useful tips for R:
  • To import/export data into/from R:
  1. Install xlsx package: install.packages("xlsx")
  2. Turn on the library: library(xlsx)
  3. For example, there is excel workbook called 'mydata' and you want to upload a data from its worksheet called 'Data' : myfile = read.xlsx("mydata.xlsx", sheetName = "Data")
  4. To export data from R into excel, run: write.xlsx(mydata, "myfile.xlsx")
Reference


  • Alternative package for handling Excel files:
1. Install package (first time only):
install.packages("devtools")
devtools::install_github("kassambara/r2excel")

2. To turn on the package, run:
library(r2excel)

3. Import data from Excel file:
mydata=xlsx.readFile('/pathToExcelFile/mydata.xlsx', sheetIndex = 1, header = TRUE)

Reference