0% found this document useful (0 votes)
17 views

Programming in R

This document discusses key concepts in R programming including: 1. The distinction between response and explanatory variables and appropriate statistical tests such as regression, ANOVA, and count data analysis depending on variable type. 2. Recommended graphics such as scatter plots for regression and box plots for ANOVA. 3. Basic R syntax including functions, subscripts, multi-line code blocks, and lists. 4. Factors as categorical variables that can be used for ANOVA and factors are encoded using the factor() function. 5. Dataframes created using data.frame() to store variables and the factor() function is used to encode vectors as factors.

Uploaded by

Julia S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Programming in R

This document discusses key concepts in R programming including: 1. The distinction between response and explanatory variables and appropriate statistical tests such as regression, ANOVA, and count data analysis depending on variable type. 2. Recommended graphics such as scatter plots for regression and box plots for ANOVA. 3. Basic R syntax including functions, subscripts, multi-line code blocks, and lists. 4. Factors as categorical variables that can be used for ANOVA and factors are encoded using the factor() function. 5. Dataframes created using data.frame() to store variables and the factor() function is used to encode vectors as factors.

Uploaded by

Julia S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

R PROGRAMMING LANGUAGE

Firstly, make sure that you know the distinction between your response variable and

your explanatory variable.

Then, you need to select the kind of statistics you need to employ:

(1) If your response variable is a count, where you typically have lots of zeros, then you

will want to use either:

a) the classical tests

b) count data in tables.

(2) If your response variable is a continuous measure (e.g., a weight), then you will

want to use either:

a) regression if your explanatory variable is continuous (e.g., an altitude);

b) analysis of variance if your explanatory variable is categorical (e.g.,

genotype).

Do not forget to use the appropriate graphics:

a) scatter plots for regression;

b) box and whisker plots for ANOVA.


Recognising mathematical functions is straightforward: names + the fact that
their arguments are enclosed in round brackets ().

Subscripts on objects have square brackets [].

Multi-line blocks of R code are enclosed within curly brackets {}.

Elements within lists have double square brackets [[]].

Type CTRL + S to save the contents of R editor window and name it.

Factors are categorical variables that have a fixed number of levels. A simple
example might be a variable called gender with two levels: female and male.
In statistical modelling, factors are associated with analysis of variance (all of
the explanatory variables are categorical) and analysis of covariance (some of the
explanatory variables are categorical and some are continuous).

To create a dataframe, use data <-; the function data.frame() creates data frames,
tightly coupled collections of variables which share many of the properties of
matrices and lists, used as the fundamental data structure by R.

The function factor is used to encode a vector as a factor (the terms category and
enumerated type are also used for this). Vector as character strings. A factor can be
compared to another factor with an identical set of levels (although not necessarily in
the same ordering). To turn factor levels into integers, use the unclass function.
Factors are stored internally as integers, so their mode=numeric.

You might also like