R Tips and Tricks

setwd(”) # Set working directory
install.packages(”) # Requires ”

factor(x, levels = c(1, 2, 3), labels = c(‘a’, ‘b’, ‘c’)) # Use this to reorder or relabel factors

subset(x, condition, select = c(variable)) # Can use : to refer to range or variables. Leave condition blank for reordering or leaving out variables
substr(x, start_char, end_char)

gsub(string_to_replace, string_that_replaces, x)
grep(string_to_find, x) # Returns index which can then be put used to call elements from data frame

for(x in range) {}

variable = list(c(name = object)) # Use names(variable) to call object name from list

One thought on “R Tips and Tricks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s