How can I assign the same length n to multiple vectors, in one go?
At the moment I am stuck doing
length(vector_1) <- n
length(hello) <- n
....
....
length(cat) <- n
Many thanks
If your vectors need to be the same length then it is likely that they are all related somehow. If they are related then it is usually better to collect them all together into a single object rather than having them as individual vectors in the global workspace. One option would be to put them all in a list together. Once in the list you can loop through the list (for loop or `lapply' function) and assign the length to each element. A data frame (which is stored as a list, so the above would work the same) is another way to store vectors that requires them to be the same length.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With