We can read data in this way…
library(gdata)
## gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
##
## gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.
##
## Attaching package: 'gdata'
##
## The following object is masked from 'package:stats':
##
## nobs
##
## The following object is masked from 'package:utils':
##
## object.size
df = data.frame(read.xls ("custdata.xlsx", header=TRUE, perl="/usr/bin/perl"))
head(df,5)
## custid sex is.employed income marital.stat health.ins
## 1 2068 F NA 11300 Married 1
## 2 2073 F NA 0 Married 1
## 3 2848 M 1 4500 Never Married 0
## 4 5641 M 1 20000 Never Married 0
## 5 6369 F 1 12000 Never Married 1
## housing.type recent.move num.vehicles age state.of.res
## 1 Homeowner free and clear 0 2 49 Michigan
## 2 Rented 1 3 40 Florida
## 3 Rented 1 3 22 Georgia
## 4 Occupied with no rent 0 0 22 New Mexico
## 5 Rented 1 1 31 Florida
Or this way…
library(readxl)
sample <- system.file("extdata", "custdata.xlsx", package="readxl")
df2 = read_excel("custdata.xlsx", col_names=TRUE)
head(df2, 5)
## custid sex is.employed income marital.stat health.ins
## 1 2068 F NA 11300 Married 1
## 2 2073 F NA 0 Married 1
## 3 2848 M 1 4500 Never Married 0
## 4 5641 M 1 20000 Never Married 0
## 5 6369 F 1 12000 Never Married 1
## housing.type recent.move num.vehicles age state.of.res
## 1 Homeowner free and clear 0 2 49 Michigan
## 2 Rented 1 3 40 Florida
## 3 Rented 1 3 22 Georgia
## 4 Occupied with no rent 0 0 22 New Mexico
## 5 Rented 1 1 31 Florida