# Set the working directory setwd("D:/Programming Guide/R Guide/code") ### 2.1 Packages # Use the readxl library to get the data library (readxl) ### 2.2 Importing data UKHP <- read_excel("D:/Programming Guide/data/UKHP.xls ", col_types = c("date", "numeric")) # Show the data View (UKHP) # Data classes class(UKHP) # Variable names names(UKHP) # First 6 observations head(UKHP) # Last 6 observation tail(UKHP) ### 2.3 Data description # Summary statistics summary(UKHP) x = mean(UKHP$'Average House Price') x x <- mean(UKHP$'Average House Price') x ### 2.4 Changing and creating data names(UKHP)[2] = "hp" names(UKHP) # Writing a new variable; return dhp UKHP$dhp = c(NA,100*diff(UKHP$hp)/UKHP$hp[1:nrow(UKHP)-1]) head(UKHP$dhp) dhp = 100*diff(UKHP$hp)/UKHP$hp[1:nrow(UKHP)-1] head(dhp) ### 2.5 Graphs and plots # Time series plot par(cex.axis = 1.5,cex.lab = 1.5,lwd = 2) plot(UKHP$Month,UKHP$hp,type = 'l',xlab ="Date",ylab ="House price",main = "Average house price") # Histogram hist(UKHP$hp) box() ### 2.6 Keeping track of your work