Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #Reading in File
  2. table<- read.csv("C:~table.csv", header = TRUE)
  3. table[] <- lapply(First33000n, as.character)
  4. table <- as.data.table(First33000n[,c(2,3,4)])
  5. #Initializing Tracking Variables
  6. table[,checked:=0]
  7. table[,results:=character]
  8. table[,percentages:=character]
  9.  
  10. #Starting Loop over column of table
  11. for (i in 1:NROW(table)){
  12.  
  13. #Writing full chain of operations for first desired output
  14. txt<-tryCatch(readLines(table[i,websiteURL]), error = function(e) table[i,error:=1]) %>%
  15. paste(collapse = " ", .) %>%
  16. gsub("&nbsp;", " ", .) %>%
  17. strsplit("\t") %>% unlist() %>%
  18. grep("influx pattern", x = ., value = TRUE, ignore.case = TRUE) %>%
  19.  
  20. #First desired output
  21. gsub("^\s?", "", x = .) %>%
  22. table[i,results:=paste(txtn, collapse = " / ")]
  23.  
  24.  
  25.  
  26. #Rewriting full chain of operations again for second desired output with different variables
  27. txt2<-tryCatch(readLines(table[i,websiteURL]), error = function(e) table[i,error:=1]) %>%
  28. paste(collapse = " ", .) %>%
  29. gsub("&nbsp;", " ", .) %>%
  30. strsplit("\t") %>% unlist() %>%
  31. grep("influx pattern", x = ., value = TRUE, ignore.case = TRUE) %>%
  32.  
  33. #Second desired output
  34. str_extract_all(., "\d+(\.\d+){0,1}%") %>%
  35. table[i,percentages:=paste(txtn2, collapse = " / ")]
  36.  
  37. table[i,checked:=1]
  38. }
  39.  
  40. #Reading in File
  41. table<- read.csv("C:~table.csv", header = TRUE)
  42. table[] <- lapply(First33000n, as.character)
  43. table <- as.data.table(First33000n[,c(2,3,4)])
  44. #Initializing Tracking Variables
  45. table[,checked:=0]
  46. table[,results:=character]
  47. table[,percentages:=character]
  48.  
  49. #Starting Loop over column of table
  50. for (i in 1:NROW(table)){
  51.  
  52. #Writing full chain of operations for both desired outputs and naming resultant object ".."
  53. txt<-tryCatch(readLines(table[i,websiteURL]), error = function(e) table[i,error:=1]) %>%
  54. paste(collapse = " ", .) %>%
  55. gsub("&nbsp;", " ", .) %>%
  56. strsplit("\t") %>% unlist() %>%
  57. grep("influx pattern", x = ., value = TRUE, ignore.case = TRUE) -> ..
  58.  
  59.  
  60. #First operation I want to be done to the newly named object ".."
  61. gsub("^\s?", "", x = ..) -> a %>%
  62. table[i,results:=paste(a, collapse = " / ")]
  63.  
  64.  
  65. #Second operation I want to be done to the newly named object ".."
  66. str_extract_all(.., "\d+(\.\d+){0,1}%") ->b %<>%
  67. table[i,percentages:=paste(b, collapse = " / ")]
  68.  
  69. table[i,checked:=1]
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement