An intro to R
basic_r_intro.RmdUNDER DEVELOPMENT…
This document is a quick introduction to basic R. Audience would be users who are not familiar with R.
R syntax
- Dot “.” is valid in a variable name or a function (e.g. variable
element.subset, functionModelArray.lm()) - Syntax for formula: Below is an example formula:
formula <- FD ~ age + sexAs you can see even though we did not define variable “FD”,“age” or “sex”, it’s a valid formula. Left hand side of “~” is dependent variable (y, or response), and right hand side includes the independent variables / covariates.
Prepare the phenotypes data.frame: manipulations
You may want to manipulate the data.frame phenotypes
before passing it to ModelArray.lm() etc functions for
model fitting. Examples like de-mean and rescale covariates. R package
dplyr is useful and easy to use for manipulation.
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union