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! 🙂
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
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: