Skip to content

Instantly share code, notes, and snippets.

@BillPetti
Last active May 27, 2017 13:48
Show Gist options
  • Save BillPetti/cf1e082b5e580b3b7209 to your computer and use it in GitHub Desktop.
Save BillPetti/cf1e082b5e580b3b7209 to your computer and use it in GitHub Desktop.
A quick function for creating a convenient variable reference table in R
# Quick script to make a more readable list of variables and attributes for dataframes in RStudio.
# Gives variable number, name, first observation, and the variable's class and returns a dataframe
# Modeled on SPSS's Variable View
variable_list <- function(x) {
data <- x[1,]
data <- t(data)
vars <- row.names(data)
num <- 1:length(vars)
data <- as.data.frame(cbind(num,vars,data))
names(data) <- c("variable_number", "variable_name", "first_observation")
row.names(data) <- NULL
class <- sapply(x, class)
data$class <- class
data <- data[,c(2,1,4,3)]
data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment