Created
August 17, 2016 18:20
-
-
Save anarosner/c3d04f44f9dfea1dc8ff3c4ae15014f8 to your computer and use it in GitHub Desktop.
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
create_relational <- function( df, col, id_col="join_id", join_name="join_name" ) { | |
if( !is.factor(df[,col]) ) | |
df[,col] <- as.factor(df[,col]) | |
df[,id_col] <- unclass( df[,col] ) | |
join_table <- data.frame( x=attr(unclass(df[,col]),"levels") ) | |
names(join_table) <- join_name | |
join_table[,id_col] <- 1:length(attr(unclass(df[,col]),"levels")) | |
join_table[,join_name] <- as.character( join_table[,join_name] ) | |
return( list(df=df, join_table=join_table) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment