There are a variety of useful functions in R. Below is a brief listing.
Some functions live in a different library. In this page, these are
shown with the library name in front, such as
readr::parse_integer(). You can run these using two
different methods:
# Option 1: include the package name before the function name
readr::parse_integer(c('1', '2'))
## [1] 1 2
# Option 2: load the library, and then use the function
library(readr)
parse_integer(c('1', '2'))
## [1] 1 2
median()/mean()/max()/min()/sum()abs() - absolute valueround() - rounds 1.2 to 1seq(from, to, increment) - returns a sequence from
-> to (skipping every increment)rep(x, times) - return a new vector of x, repeated
times.In the readr library:
readr::parse_integer(): turns “1” into 1
NAparse_integer( x = c('1', '2', 'X', '?'), na = c('?', 'X'))paste0(text1, text2, ...): combine text valuespaste(text1, text2, ..., sep = ',' ): combines text,
split with sepView(data): opens data in a nice gui. Note that it is
capitalized!names(data): what are the field names of the data?sort()/rev(): order items in a vectorvector_a <- append(vector_a, new_item_or_vector_of_items):
create a new vector with the additional itemsunlist(): turn a list into a vectorplot(): create a basic x/y plottable(): create a crosstabcor(): calculate correlationis_*(): test for types (convert * to integer,
etc…)as_*(): convert a type