Last active
May 27, 2017 13:48
-
-
Save BillPetti/cf1e082b5e580b3b7209 to your computer and use it in GitHub Desktop.
A quick function for creating a convenient variable reference table in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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