You are doing great! Now it's time for a little wrap up of R syntax!
- To assign a value to a variable use the
- Put string values in double quotes (
"This is a text") or single quotes (
'This is also a text').
- There are two logical values in R:
FALSE. We can use the following logical operators:
- A missing or unknown value is denoted by
NA in R.
- Vectors let us store multiple values in one object. To create a vector use the
family.age <- c(15,19,22,67,65)
- To create a factor, use the
factor(vector, levels) function. The first argument gives values, the other specifies levels. If any value from vector is not listed in levels it would be changed to
- A data frame is R's way to store table data.
family <- data.frame(
name = c('Anna','Mark','Tom'),
age = c(30,32,28)
height = c(175, 180, 188))
- To access specific elements from a data frame specify their positions in square brackets:
The first vector is for rows, the second is for columns.
- To narrow a data frame to certain rows, specify the row vector and omit the column vector:
- To narrow a data frame to certain columns, specify the column vector and omit the row vector:
- To get a whole column from a given data frame use the
$ sign with the column name: