Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.40 KB | None | 0 0
  1. # Use paste function here to split string, so it fits into 80
  2. # characters as linter rules require
  3. link = paste("https://raw.githubusercontent.com/", "go95/big_data_intro/master/Abdulkadiroglou.csv", sep = "")
  4.  
  5. articles <- read.csv(url(link))
  6.  
  7. # assign 9th column of data frame to a vector
  8. cit_num_vector <- articles[,9]
  9.  
  10. # filter out NA values
  11. cit_num_vector <- cit_num_vector[!is.na(cit_num_vector)]
  12.  
  13. # sort the vector
  14. cit_num_vector_sorted <- sort(cit_num_vector)
  15.  
  16. Np <- length(cit_num_vector_sorted)
  17.  
  18. # The resulting table will have Np rows and 2 columns
  19. res_table <- matrix(0:0, nrow = Np, ncol = 2)
  20.  
  21. curr_val <- 0
  22. c <- 1
  23.  
  24. # Cycing through cit_num_vector
  25. for (i in 1:length(cit_num_vector_sorted)) {
  26.     # If it is a next unique value in the vector
  27.     if (curr_val != cit_num_vector_sorted[i]) {
  28.         # assign the first row of c-th column
  29.         res_table[c, 1] <- cit_num_vector_sorted[i]
  30.  
  31.         # Np in this case will be equal to Np - i + 1
  32.         res_table[c, 2] <- Np - i + 1
  33.  
  34.         # Assign a new value to curr_val to check
  35.         # next values for uniqueness
  36.         curr_val <- cit_num_vector_sorted[i]
  37.  
  38.         # Add 1 to counter variable
  39.         c <- c + 1
  40.     }
  41. }
  42.  
  43. # Cycling through res_table
  44. for (i in 1:Np) {
  45.     cit_num <- res_table[i, 1]
  46.     count <- res_table[i, 2]
  47.     if (cit_num > count) {
  48.         break
  49.     }
  50.     res <- res_table[i, 1]
  51. }
  52.  
  53. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement