R Program Cheat Sheet 1
R Program Cheat Sheet 1
RStudio® is a trademark of RStudio, Inc. • CC BY Mhairi McNeill • [email protected] Learn more at web page or vignette • package version • Updated: 3/15
Types Matrixes Strings Also see the stringr library.
m <- matrix(x, nrow = 3, ncol = 3) paste(x, y, sep = ' ')
Converting between common data types in R. Can always go Join multiple vectors together.
Create a matrix from x.
from a higher value in the table to a lower value.
paste(x, collapse = ' ') Join elements of a vector together.
m[2, ] - Select a row t(m)
grep(pattern, x) Find regular expression matches in x.
as.logical TRUE, FALSE, TRUE Boolean values (TRUE or FALSE). Transpose
w
ww m %*% n gsub(pattern, replace, x) Replace matches in x with a string.
m[ , 1] - Select a column
Integers or floating point
as.numeric 1, 0, 1
numbers.
ww
w Matrix Multiplication toupper(x) Convert to uppercase.
ww solve(m, n)
w tolower(x) Convert to lowercase.
Character strings. Generally ww
w m[2, 3] - Select an element Find x in: m * x = n
as.character '1', '0', '1' nchar(x)
preferred to factors. Number of characters in a string.
RStudio® is a trademark of RStudio, Inc. • CC BY Mhairi McNeill • [email protected] • 844-448-1212 • rstudio.com Learn more at web page or vignette • package version • Updated: 3/15