Skip to content

Instantly share code, notes, and snippets.

@crsh
Last active April 17, 2019 21:42
Show Gist options
  • Save crsh/db06d3cc81599d92fda6 to your computer and use it in GitHub Desktop.
Save crsh/db06d3cc81599d92fda6 to your computer and use it in GitHub Desktop.
Demonstration of variable.labels attribute in RStudio Viewer and Hmisc::label
label_test <- cars
attr(label_test, "variable.labels") <- c("Speed (km/h)", "Distance traveled (km)")
View(label_test)
str(label_test) # data.frame attribute
# Alternative using Hmisc (does not show up in RStudio Viewer)
label_test <- cars
Hmisc::label(label_test$speed) <- "Speed (km/h)"
Hmisc::label(label_test$dist) <- "Distance traveled (km)"
str(label_test) # Column specific attributes
@crsh
Copy link
Author

crsh commented Oct 8, 2015

variable_labels

@crsh
Copy link
Author

crsh commented Oct 12, 2015

The package haven also uses an attribute called label for each variable to import labels from SPSS, STATA, or SAS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment