I am trying to add a column with repetitive values to an existing dataframe. There are 8 values to be repeated and it should be repeated untill the end of the existing dataframe. I used the code below and got back the Error as below.
I think it has something to due with the fact that the length of the new col1
always comes in multiplies of 8. While the existing dataframe is from a different length.
Any idea how to make the rep
function stop at the end of the lentgh of my df? (and thereby making the last rep to stop in the middle of a rep).
Thnx
df1$col1 <- rep(c("row_A", "row_B", "row_C", "row_D", "row_E", "row_F", "row_G", "row_H"), length(df1))
Error:
! Assigned data `rep(...)` must be compatible with existing data.
✖ Existing data has 164 rows.
✖ Assigned data has 120 rows.
ℹ Only vectors of size 1 are recycled.