ECON 413
Basic R functions


Erol Taymaz
Department of Economics
Middle East Technical University

Utilities

install.packages, update.packages, library, require

setwd, getwd

?, ??, rm, ls, ls.str, system.time, object.size

Key operators

<- or = (use <-)

:

c

Basic math

*, +, -, /, ^, %%, %/%, %*%

abs, sign, acos, asin, atan, atan2, sin, cos, tan

ceiling, floor, round, trunc, signif

exp, log, log10, log2, sqrt

sum, cumsum, cummax, shift, lead, lag

mean, sd, min, max, pmax, pmin

%in%, %between%

Logical

&, |, !, xor

Frequently used functions

str, class, summary, describe, head, tail

table, xtabs, dim, ncol, nrow, length, nchar, names

subset

factor, ordered

Vector and data functions

vector, matrix, array, list, numeric, character

rep, seq

data.frame, data.table

cbind, rbind, merge, reshape

identical, na.omit

within, with

is. and as. functions

is.numeric, is.integer, …

as.numeric, as.integer, as.data.frame, …

Random number generators

set.seed, sample

rnorm, runif, …

Date functions

as.Date, months, weekdays, …

Loops

for, while, repeat

stop, break, next

String functions

paste, paste0

substr

sub, gsub

grep, grepl, regexpr, gregexpr, regexec

System functions

Sys.getlocale, Sys.setlocale(“LC_TIME”, “tr_TR.utf8”)

Sys.info, Sys.time, Sys.date

Interactions

cat, print

readline

Sys.sleep

Reading and writing files

read.csv, read.table, write.csv

load, save

fread, fwrite

read.xls, read_stata

Constants

pi, letters, LETTERS, month.abb, month.name

Indexing

[

[[