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
R - Add Column That Counts Sequentially Within Groups But Repeats for Duplicates
More Than One Value for "Each" Argument in "Rep" Function
Creating "Radar Chart" (A.K.A. Star Plot; Spider Plot) Using Ggplot2 in R
Error in If/While (Condition) {:Argument Is of Length Zero
How to Read Data in Utf-8 Format in R
Draw the Sum Value Above the Stacked Bar in Ggplot2
Duplicates in Multiple Columns
Select Only the First Row When Merging Data Frames with Multiple Matches
Date Conversion from Posixct to Date in R
How to Insert New Line in R Shiny String
Center X and Y Axis with Ggplot2
Remove Everything After Space in String
Concatenate Strings and Expressions in a Plot's Title