Skip to content

Instantly share code, notes, and snippets.

View Oreotrephes's full-sized avatar

Robbie Hart Oreotrephes

View GitHub Profile
require(rvest)
output_file_name<-'output.txt'
for(i in 6174:45000){ #or 1, or whatever
url <- paste0("http://naeb.brit.org/uses/",i) #
message("Scraping ", url)
use_page_i <- read_html(paste0("http://naeb.brit.org/uses/",i))
links_i <- use_page_i %>% html_elements("a")
species_i <- links_i[8] %>% html_text2()
write(species_i,file=output_file_name,append=TRUE)
}
require(dplyr)
#Goal - collapse information from duplicate rows
name<-c("John","John","Frank","Frank","Sue","Sue","Bob")
rank<-c("","sergeant",""," ","lieutenant","major","")
force<-c("army","","navy","navy","army","army","navy")
testdf<-data.frame(name,rank,force)
testdf
#okay this seems to work fine:
#out of 816 rows to start with
#extracts corolla lengths for 611
#capsule lengths for 436
#both for 432
#I've checked the first 15 rows or so and spot check othres and this seems to be working.
#However, I'm don't know why the first function (capsule) seems to want greedy (ie. "capsule.*)
#while the second function (corolla) seems to want nongreedy (ie. "corolla.*?)
market.compare<-function(market.name,df,uses){
this.market.uses<-df[df$Market==market.name,uses]
other.market.uses<-df[df$Market!=market.name,uses]
this.market.unique<-setdiff(this.market.uses,other.market.uses)
this.market.total<-unique(this.market.uses)
percent.unique<-length(this.market.unique)/length(this.market.total)
percent.unique
}
market.compare("Calle Santa Cruz",sample,"Medicinal.Use.categories")
@Oreotrephes
Oreotrephes / gist:578ff38669a579ced2cb
Last active August 29, 2015 14:10
At-a-glance coefficient table
#looks familiar
summaryfunction2<-function(x,y){
signs<-substr(as.character(sign(x)),1,1)
signs[signs=="1"]<-"+"
significance<-cut(abs(y), c(0, 0.001, 0.01, 0.05, Inf), labels=c("***", "**", "*", ""), right=FALSE)
paste(signs, significance)
}
#use that function in a function
process<-function(lm){
@Oreotrephes
Oreotrephes / gist:e57e629c5458ccc96a2d
Created December 2, 2014 23:01
At-a-glance coefficient table
summaryfunction2<-function(x,y){
signs<-substr(as.character(sign(x)),1,1)
signs[signs=="1"]<-"+"
significance<-cut(abs(y), c(0, 0.001, 0.01, 0.05, Inf), labels=c("***", "**", "*", ""), right=FALSE)
paste(signs, significance)
}
process<-function(lm){
coef<-data.frame(summary(lm)$coefficients)[-1,-c(2,3)]
coef$comb<-summaryfunction2(coef$Estimate,coef$Pr...t..)
@Oreotrephes
Oreotrephes / gist:c0c3780a06ded1a5dc6e
Created December 2, 2014 23:01
At-a-glance coefficient table
summaryfunction2<-function(x,y){
signs<-substr(as.character(sign(x)),1,1)
signs[signs=="1"]<-"+"
significance<-cut(abs(y), c(0, 0.001, 0.01, 0.05, Inf), labels=c("***", "**", "*", ""), right=FALSE)
paste(signs, significance)
}
process<-function(lm){
coef<-data.frame(summary(lm)$coefficients)[-1,-c(2,3)]
coef$comb<-summaryfunction2(coef$Estimate,coef$Pr...t..)
@Oreotrephes
Oreotrephes / gist:35e7052d54f97c7eca0f
Last active August 29, 2015 14:10
vectorization fail
summaryfunction<-function(x){
a<-if(is.na(x)){"NA"} else if(x<0){"-"} else {"+"}
b<-if(is.na(x)){"NA"} else if(abs(x)<0.001){"***"} else if(abs(x)<0.01){"**"} else if(abs(x)<0.05){"*"} else{" "}
paste(a,b)
}
#individually are fine
summaryfunction(listy[1])
summaryfunction(listy[2])
#It aint pretty but it works
###################################################################################################################################
classify <- function(dendrogram,height){
#this little function will return tip lables
members <- function(n) {
labels<-c()
if (is.leaf(n)) {
a <- attributes(n)
#ALL THIS IS IN TERMINAL
#First, install gpsbabel through some means. I have homebrew, so I did
$ brew install gpsbabel
#Navigated to wherever the gpx files are
$ cd ~/Downloads/activities
#and converted them
$ for i in *.gpx; do gpsbabel -t -i gpx -f $i -o unicsv -F $i.csv; done
#runs enormously fast!
#okay, so how long are all those put together?