Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Get libraries
- library(data.table)
- library(ggplot2)
- # Data table for demo
- data <- data.table("Bad names" = 1:100, "Shouldn't use spaces" = rep(c("text","other"),100))
- # Store the original names
- # Changing this to c(names(data)) solves the problem but is a hack
- original.names <- names(data)
- # Update the data's column names
- setnames(data, old = names(data),new = c("V1","V2"))
- # Now original.names has also been changed to the new names
- # However, only the names of the data should have changed.
- cat(original.names,"n", names(data))
- # Random ggplot
- ggplot(data) + geom_bar(aes(V1))
- # Rename data
- setnames(data, names(data), original.names)
- # I still get names V1 and V2, it is as if original names has been changed globally.
- cat(names(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement