Skip to content

Instantly share code, notes, and snippets.

@maartenvanvliet
Last active August 29, 2015 14:05
Show Gist options
  • Save maartenvanvliet/e29930145551f36d8758 to your computer and use it in GitHub Desktop.
Save maartenvanvliet/e29930145551f36d8758 to your computer and use it in GitHub Desktop.
R convenience helpers
#First differences, NA for first value
diff_na <- function(vector){
return c(NA, diff(value))
}
#Renames column
col.mv <- function(dataframe, old_name, new_name){
names(dataframe)[names(dataframe)==old_name] <- new_name
return dataframe
}
#convert numbers with commas to integers
comma_numbers_to_int <- function(col){
strtoi(gsub(",", "", c))
}
#delete column
col.rm <- function(df,col){
df[, !(colnames(df) %in% c(col))]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment