More Than One Value for "Each" Argument in "Rep" Function

More than one value for each argument in rep function?

Depending on what you think the output should be, I'm guessing you want the times= parameter:

rep (a, times = c(2, 4, 7))
# [1] 2 2 4 4 4 4 6 6 6 6 6 6 6

See ?rep for the difference

using rep function to create repetition multiple times

With one expression you can use both the times and each arguments:

rep(c("aut","win","sum"), each=520, times=16)

Iterate through times argument in rep()-function and store result in new variable in R

Does this help?

for(i in 1:15){
assign(paste0("a",i,"b"), rep(c(1540), times = df[i]))
}

If you want to create a variable name from a string assign() is your friend. The second argument is an object (in this a vector) that is assigned to the variable name given (as a string) in the first argument.

rep() with each equals a vector

rep(1:5, vect1)

If you have questions about how to work functions in R, try

?function

where "function" is whatever function you want to know about. From ?rep you would have read:

'times' A integer vector giving the (non-negative) number of times to repeat
each element if of length length(x), or to repeat the whole vector if
of length 1. Negative or NA values are an error.



Related Topics



Leave a reply



Submit