I am trying to write a function that takes a list of vectors, finds the vector with minimum length, and then makes all other vectors in the list that size.
This is what I have so far:
I first create the list of vectors,
data_list <- as.list(vector1, vector2, etc)
Then, I start writing the "trim" function to find vectors that are longer than the vector of smallest length, and reduce their length to the minimum length:
trim <- function(list){
lengths_list <- lengths(list)
min_length <- min(length_numbers)
for(i in list){
if(i > min_length){
list[i] <- list[-1:-min_length]
}
else{
next
}
}
}
When I apply this function to my list of vector, nothing happens. The lengths of the vectors do not change.
What am I doing wrong?
Thanks!