Cycle Through Columns

KEY:

ds = dataset you are currently using.

Var = variable to be displayed 

optional, etc. = where any optional commands belong

XYXY <- variable into which data is being saved

Topics:

These code blurbs are designed to speed up the first pass-through of data analysis. They use for-loops to do a quick visual check of the state of your variables. Simply press "enter" to cycle through.

NOTE: Many of these visualization are dependent on the type of data you are examining. You may want to copy same-time variables (e.g., categorical, numeric) to type-specific data frames, in order to avoid errors.

Bar Plots

Bar plots for categorical data. 

_______________________________

for (i in 1:length(XYXY)){

  print(barplot(table(XYXY[,i]), 

                xlab = colnames(XYXY[i]),

                axis.lty = "solid"))

  readline(prompt="Press [enter] to continue")

}

_______________________________

 

Histograms (with skew)

This will provide the histogram with skew value in the title. Note that skew comes from e1071, so you will need to download this package.

_______________________________

library(e1071)

 

for (i in 1:length(XYXY)){

  skewVal <- skewness(XYXY[,i])

  print(histogram(XYXY[,i],

                  xlab = colnames(XYXY[i]),

                  main = paste0("Skewness = ", skewVal)))

  readline(prompt="Press [enter] to continue")

}

_______________________________

 

Normality (with Shapiro-Wilk test)

Shapiro-Wilk results appear in the title

_______________________________

for (i in 1:length(XYXY)){

  normVal <- shapiro.test(XYXY[,i])

  qqnorm(XYXY[,i], 

         xlab = colnames(XYXY[,i]),

         main = paste0("Shapiro-Wilk test = ", normVal$p.value))

  qqline(XYXY[,i])

  readline(prompt="Press [enter] to continue")

}

_______________________________

 

Scatter Plot

Note that the way this is set up, column 1 will always be on the y-axis, and the other columns will cycle along the x-axis. Adjust as needed.

_______________________________

for(i in 2:length(XYXY)){

  print(plot(XYXY[,1]~XYXY[,i],

        ylab = colnames(XYXY[1]),

        xlab = colnames(XYXY[i])))

  readline(prompt="Press [enter] to continue")

}

_______________________________