diff --git a/data_manipulation/shorten.vector.R b/data_manipulation/shorten.vector.R new file mode 100644 index 0000000..00460f2 --- /dev/null +++ b/data_manipulation/shorten.vector.R @@ -0,0 +1,23 @@ +shorten.vector <- function(vector,by){ + # get last elements + vec_new <- vector |> tail(by) + + # get index of last elements + index <- c() + for(i in vec_new){ + values <- which(vector == i) + index <- c(index,values) + } + + # delete index from vector + final_vec <- vector[-c(index)] + + # return final output + return(final_vec) + + +} + +fruits <- c("Pear","Banana","Peach","Grape","Apple","Orange") + +shorten.vector(fruits,by = 1)