Introduction To R Programming
Introduction To R Programming
The help() function and ? help operator in R provide access to the documentation pages
for R functions, data sets, and other objects, both for packages in the standard R
distribution and for contributed packages.
To access documentation for the standard lm (linear model) function, for example, enter
the command help(lm) or help("lm"), or ?lm or ?"lm" (i.e., the quotes are optional).
To access help for a function in a package that’s not currently loaded, specify in
addition the name of the package:
For example, to obtain documentation for the rlm() (robust linear model)
function in the MASS package, help(rlm, package="MASS").
Creating Variables in R
Variables are containers for storing data values.
R does not have a command for declaring a variable.
A variable is created the moment you first assign a value to it.
To assign a value to a variable, use the <- sign.
To output (or print) the variable value, just type the variable name
Variable Names
• A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
• Rules for R variables are:
i) A variable name must start with a letter and can be a combination of letters, digits,
period(.) and underscore(_). Ex: vn_4
If it starts with period(.), it cannot be followed by a digit.
ii) A variable name cannot start with a number or underscore (_)
iii) Variable names are case-sensitive (age, Age and AGE are three different variables)
iv) Reserved words cannot be used as variables (TRUE, FALSE, NULL, if...)
Basic Data Types in R
• Variables can store data of different types, and different types can do different things.