Created
September 11, 2012 08:55
-
-
Save fearofcode/3697023 to your computer and use it in GitHub Desktop.
matrix row/column indexing in R + csv input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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