Skip to content

Commit b46d3ac

Browse files
authored
Add shorten.vector.R (#143)
1 parent 191af3f commit b46d3ac

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

data_manipulation/shorten.vector.R

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
shorten.vector <- function(vector,by){
2+
# get last elements
3+
vec_new <- vector |> tail(by)
4+
5+
# get index of last elements
6+
index <- c()
7+
for(i in vec_new){
8+
values <- which(vector == i)
9+
index <- c(index,values)
10+
}
11+
12+
# delete index from vector
13+
final_vec <- vector[-c(index)]
14+
15+
# return final output
16+
return(final_vec)
17+
18+
19+
}
20+
21+
fruits <- c("Pear","Banana","Peach","Grape","Apple","Orange")
22+
23+
shorten.vector(fruits,by = 1)

0 commit comments

Comments
 (0)