Skip to content

Instantly share code, notes, and snippets.

@Myfanwy
Last active August 14, 2019 20:30
Show Gist options
  • Save Myfanwy/231fcbc35caccde3b000459eb93f2470 to your computer and use it in GitHub Desktop.
Save Myfanwy/231fcbc35caccde3b000459eb93f2470 to your computer and use it in GitHub Desktop.
parse_tag_info.r
# 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