I'm not exactly sure how to ask the question since english isn't my first language. What I want is duplicate each unique id
rows 13 times and create a new column which contains rows with value ranging from -8 to 4
to fill those 13 previously duplicated rows. I think my sample data and expected data will provide a better explanation.
sample data:
data <- data.frame(id = seq(1,100,1),
letters = sample(c("A", "B", "C", "D"), replace = TRUE))
> head(data)
id letters
1 1 A
2 2 B
3 3 B
4 4 C
5 5 A
6 6 B
the expected data:
newcol id letters
1 -8 1 A
2 -7 1 A
3 -6 1 A
4 -5 1 A
5 -4 1 A
6 -3 1 A
7 -2 1 A
8 -1 1 A
9 0 1 A
10 1 1 A
11 2 1 A
12 3 1 A
13 4 1 A
14 -8 2 B
15 -7 2 B
16 -6 2 B
17 -5 2 B
So I guess I could say that I want to create a new column wit values ranging from -8 to 4 (so 13 different values) for each unique rows in the id
column.
Also if possible I would like to know how to do it in base R in with the data.table package.
Thank you and sorry for my poor grammar.