Created
June 5, 2019 21:57
-
-
Save bfatemi/7afb700d920d9f94e6a7a712b807944c to your computer and use it in GitHub Desktop.
Better way to define a data.table (implement using structure)
This file contains hidden or 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
# Usecases: | |
# when creating many R environments and each have independent data-set | |
ll <- list( | |
as.factor(c(2001, 2002, 2004, 2006)), | |
I(c(2001, 2002, 2004, 2006)), | |
ordered(c(2001, 2002, 2004, 2006)), | |
as.double(c(366.3240, 365.4124, 366.5323423, 364.9573234)), | |
list(list(letters), list(LETTERS), list(), list()) | |
) | |
dd3 <- structure( | |
.Data = ll, | |
.Names = c("year", "AsIs Year","yearO", "length of days", "more"), | |
.typeOf = c("factor", "numeric", "ordered","numeric", "list"), | |
row.names = c(NA, -4L), | |
class = "data.frame", | |
comment = "Ordered YearO for categorical analysis and other variables" | |
) | |
dd3 | |
attributes(dd3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment