Last active
August 14, 2019 20:30
-
-
Save Myfanwy/231fcbc35caccde3b000459eb93f2470 to your computer and use it in GitHub Desktop.
parse_tag_info.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
# separates the vemco column formatting of freq-codespace-tagid, then returns the original dataframe with the codespace and tagids as separate columns | |
parse_tag_info <- function(df, tagcol = "TagID") { | |
names(df)[names(df) == tagcol] <- "SepTagID" # rename the old combined tagid col | |
out <- as.data.frame(do.call(rbind, strsplit(as.character(df$SepTagID),'-')), | |
stringsAsFactors = FALSE) | |
colnames(out) <- c("freq", "CodeSpace", "TagID") | |
final <- cbind(df, out) | |
drops <- c("freq", "SepTagID") | |
final <- final[ , !names(final) %in% drops] | |
final$CodeSpace <- as.integer(final$CodeSpace) | |
final$TagID <- as.integer(final$TagID) | |
return(final) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment