Skip to content

Commit

Permalink
Add shorten.vector.R (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifeanyi55 authored Nov 13, 2024
1 parent 191af3f commit b46d3ac
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions data_manipulation/shorten.vector.R
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b46d3ac

Please sign in to comment.