Created
October 26, 2015 16:32
-
-
Save nickpettican/81850826a82f36c0eda8 to your computer and use it in GitHub Desktop.
sort some Galaxy-downloaded BED format
This file contains hidden or 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
names(galaxy_bed) <- c("chrom", | |
"chromStart", | |
"chromEnd", | |
"name", | |
"score", | |
"strand", | |
"blockCount", | |
"blockSizes") | |
# This shows how to 'subset' with either the $ operator or [[ | |
eg_with_square_brackets <- galaxy_bed[["chromStart"]] | |
eg_with_dollar <- galaxy_bed$chromStart | |
# The most hassle free way to sort a data frame is to use a package from the community's "tidy data" set of packages, | |
# like dplyr, tidyr etc. | |
library(plyr) #load the plyr package, which wraps the order function from base R | |
# preview the top of the sorted table | |
head(arrange(galaxy_bed, decreasing=FALSE)) | |
# observe how the decreasing parameter is passed to order by the ellipsis in plyr's arrange function | |
# see: http://ipub.com/r-three-dots-ellipsis/ etc for description of what the ellipsis does in an R function | |
head(arrange(galaxy_bed, galaxy_bed$name, decreasing = FALSE)) | |
head(arrange(galaxy_bed, galaxy_bed$name, decreasing = TRUE)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment