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
| 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) | |
| } |
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
| 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 |
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
| #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.*?) |
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
| 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") |
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
| #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){ |
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
| 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..) |
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
| 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..) |
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
| 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]) |
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
| #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) |
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
| #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? |