Getting data from the Web with R and some basic functionality

We will load a dataset into R and do some manipulations in order to show some basic functionality.

The dataset can be downloaded here http://www.bls.gov/oes/current/oes_ca.htm#15-0000. This dataset is a subset of the May 2014 State Occupational Employment and Wage Estimates Report in California by Computer and Mathematical Occupations. The original dataset can be found here http://www.bls.gov/oes/current/oes_ca.htm#(8).

salaries_pic1

  1. The dataset has to be downloaded in your working directory. Getwd() funcion returns an absolute filepath representing the current working directory of the R process. To change your working directory in R you need to use setwd(dir) function or go to the File menu in the R Cosole and choose “Change dir”.
  2. Create a directory for the data
if(!file.exists("salaries")) {
   dir.create("salaries")
}
  1. Download the file
fileUrl < - "your link here"
download.file(fileUrl,destfile = "./salaries/computer.xls")
  1. Next step is to install the xlsx R package if you have not done so previously. To install xlsx, use install.packages(“xlsx”), to ensure if you have it or no, enter find.package(“xlsx”) in the console. After xlsx is done installing, load it using library(xlsx).
  2. Read the file
salariesData <-read.xlsx("./salaries/computer.xls",
                         sheetIndex=1,
                         header=TRUE)
head(salariesData)

salaries_pic2
Continue reading ‘Getting data from the Web with R and some basic functionality’ »