Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created September 11, 2012 08:55
Show Gist options
  • Save fearofcode/3697023 to your computer and use it in GitHub Desktop.
Save fearofcode/3697023 to your computer and use it in GitHub Desktop.
matrix row/column indexing in R + csv input
> a <- array(1:20, dim=c(4:5))
> a
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 2 6 10 14 18
[3,] 3 7 11 15 19
[4,] 4 8 12 16 20
> a[1,]
[1] 1 5 9 13 17
> a[,2]
[1] 5 6 7 8
> path <- "/Users/warrenhenning/path/to/data/foo.csv"
> results <- read.table(path, header=TRUE, sep=",")
# or just use read.csv
> results <- read.csv(path)
# filter the table by the value of a column
> interesting_results <- subset(results, 'farts' == 'butts') # only select rows where the 'farts' column is equal to 'butts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment