<-
is known as an “assignment operator” – it means “Make the object named to the left equal to the output of the code to the right”&
means AND, in Boolean logic|
means OR, in Boolean logic!
means NOT, in Boolean logic"United States"
, or "2016-07-26"
. Numbers are not quotedc
, for combine, with the values separated by commas, for example: c("2017-07-26", "2017-08-04")
c(1:10)
creates a list of integers (whole numbers) from one to ten.+
-
add, subtract*
/
multiply, divide>
<
greater than less than>=
<=
greater than or equal to, less than or equal to!=
not equal to==
tests whether the objects on either end are equal. This is often used in filtering data=
makes an object equal to a value, which is similar to <-
but used within a function.NA
is.na(x)
looks for nulls within variable x
.!is.na(x) looks for non-null values within variable
x`Here, is.na()
is a function. Functions are followed by parentheses, and act on code/data in the parentheses.
Object and variable names in R should not contain spaces
Function | Action |
---|---|
getwd() |
List current working directory |
setwd("mydirectory") |
Change the current working directory to my directory |
ls() |
List the objects in the current work space |
rm(object) |
Delete object |
save(objectlist, file="myfile) |
Save specific objects to a file |
load("myfile") |
Load a work space into the current session (default = .RData) |
Mac users may need to alter their security preferences to allow apps authored by non-Apple developers to install. If you notice an error, try to change your system preferences.
Function | Action |
---|---|
help.start() |
General help |
help("foo") or ?foo |
Help on function foo (the quotation marks are optional) |
help.search("foo") or ??foo |
Search the help system for instances of the string foo |
example("foo") |
Examples of function foo (the quotation marks are optional) |
update.packages()
help(package=“packagename”)
search() #what packages are loaded
\
in a path name on Windows
setwd("c:\mydata")
will generate an error. Use setwd("c:/mydata")
or setwd("c:\\mydata")
insteadstr_trim()
is contained in the stringr package.© Copyright 2018, Andrew Ba Tran
© Copyright 2018, Andrew Tran