Useful R code – tips and tricks:
The R tips listed here are code and functions that I found helpful when analyzing my data.
Suggestions and comments are always welcome! 🙂

Subsetting Data
Dealing with NAs
Merge/Append using R
Automate input directories or output file names in R

Getting and Cleaning Data in R

Incorporating a variable in a String
Assigning Values to Automatically Generated Variable Names
How to automatically generate a list of variable names
How to recode variables in R (reverse-coding)
lapply (or sapply) – testing elements of a list (or column) – goodbye for loops!
Checking whether elements in an array/list are positive or negative (using sapply)
mapply – applying a function to multiple column variables
Extracting Values from R Summary Objects
How to Debug a Function in R
Check if at least two or more booleans are True in R
Comparing if two columns are the same
How to Calculate R-squared Change in R
How to summarize data and regression models by group

How to correlate a matrix with one variable

How to adjust multiple variables by a variable (regress function and apply)


R Function(s) for you to use!
R function to adjust p.values and show only thresholded correlation coefficients in matrix

Plotting in R
Selecting and visualizing only significant correlation coefficients in matrix and correlograms

Writing Data to Data Frame and Exporting Data  as .csv File [to be added…]
Build a report based on R script (knitr, stitch, markup) [to be added… ]
apply, sapply, lapply, mapply, etc.?

Additional R resources:

R- Programming wikibook
R- bloggers
R function of the day

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: