Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Use paste function here to split string, so it fits into 80
- # characters as linter rules require
- link = paste("https://raw.githubusercontent.com/",
- "go95/big_data_intro/master/Abdulkadiroglou.csv",
- sep = "")
- articles <- read.csv(url(link))
- # assign 9th column of data frame to a vector
- cit_num_vector <- articles[,9]
- # filter out NA values
- cit_num_vector <- cit_num_vector[!is.na(cit_num_vector)]
- # sort the vector
- cit_num_vector_sorted <- sort(cit_num_vector)
- Np <- length(cit_num_vector_sorted)
- # The resulting table will have Np rows and 2 columns
- res_table <- matrix(0:0, nrow = Np, ncol = 2)
- curr_val <- 0
- c <- 1
- # Cycing through cit_num_vector
- for (i in 1:length(cit_num_vector_sorted)) {
- # If it is a next unique value in the vector
- if (curr_val != cit_num_vector_sorted[i]) {
- # assign the first row of c-th column
- res_table[c, 1] <- cit_num_vector_sorted[i]
- # Np in this case will be equal to Np - i + 1
- res_table[c, 2] <- Np - i + 1
- # Assign a new value to curr_val to check
- # next values for uniqueness
- curr_val <- cit_num_vector_sorted[i]
- # Add 1 to counter variable
- c <- c + 1
- }
- }
- # Cycling through res_table
- for (i in 1:Np) {
- cit_num <- res_table[i, 1]
- count <- res_table[i, 2]
- if (cit_num > count) {
- break
- }
- res <- res_table[i, 1]
- }
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement