SHARE
TWEET

Untitled

a guest Sep 18th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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/",
  4.     "go95/big_data_intro/master/Abdulkadiroglou.csv",
  5.     sep = "")
  6.  
  7. articles <- read.csv(url(link))
  8.  
  9. # assign 9th column of data frame to a vector
  10. cit_num_vector <- articles[,9]
  11.  
  12. # filter out NA values
  13. cit_num_vector <- cit_num_vector[!is.na(cit_num_vector)]
  14.  
  15. # sort the vector
  16. cit_num_vector_sorted <- sort(cit_num_vector)
  17.  
  18. Np <- length(cit_num_vector_sorted)
  19.  
  20. # The resulting table will have Np rows and 2 columns
  21. res_table <- matrix(0:0, nrow = Np, ncol = 2)
  22.  
  23. curr_val <- 0
  24. c <- 1
  25.  
  26. # Cycing through cit_num_vector
  27. for (i in 1:length(cit_num_vector_sorted)) {
  28.     # If it is a next unique value in the vector
  29.     if (curr_val != cit_num_vector_sorted[i]) {
  30.         # assign the first row of c-th column
  31.         res_table[c, 1] <- cit_num_vector_sorted[i]
  32.  
  33.         # Np in this case will be equal to Np - i + 1
  34.         res_table[c, 2] <- Np - i + 1
  35.  
  36.         # Assign a new value to curr_val to check
  37.         # next values for uniqueness
  38.         curr_val <- cit_num_vector_sorted[i]
  39.  
  40.         # Add 1 to counter variable
  41.         c <- c + 1
  42.     }
  43. }
  44.  
  45. # Cycling through res_table
  46. for (i in 1:Np) {
  47.     cit_num <- res_table[i, 1]
  48.     count <- res_table[i, 2]
  49.     if (cit_num > count) {
  50.         break
  51.     }
  52.     res <- res_table[i, 1]
  53. }
  54.  
  55. print(res)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top