Skip to content

Instantly share code, notes, and snippets.

@geofferyzh
Created April 16, 2012 18:04
Show Gist options
  • Save geofferyzh/2400391 to your computer and use it in GitHub Desktop.
Save geofferyzh/2400391 to your computer and use it in GitHub Desktop.
RinAction - R Data Structure - Vectors
#-----------------------------------------------------------------------------#
# R in Action - R Data Structures #
# - Working with Vectors, Matrices, Arrays,Dataframes & Lists #
#-----------------------------------------------------------------------------#
#################################
# Vectors #
#################################
# creating vectors
a <- c(1, 2, 5, 3, 6, -2, 4)
b <- c("one", "two", "three")
c <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)
# Vectors with repeating values
s <- rep(C("a"),5)
s <- rep(c("a","b"),5)
s <- rep(c("a","b"),c(5,2))
s
# Using vector subscripts
a <- c(1, 2, 5, 3, 6, -2, 4)
a[3]
a[c(1, 3, 5)]
a[2:6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment