Reputation: 575
I have a column of length 1536 that contains an hourly 'count' from 1 to 1536. I JUST want to create a second column for 'day' that contains 1:7, each repeated 24 times, for the entire vector length.
Ldata$day <- rep(1:7, each=24)
The above code SHOULD work, but the damn thing keeps throwing an error of 'replacement has 168 rows, data has 1536' Why can't this code just fill in the vector as much as possible then stop? Why is that so hard/why is throwing an error even needed. Just put the sequence into the column.....
Upvotes: 1
Views: 4315
Reputation: 575
You can specify both the 'each' and 'length.out' parameters of rep()
:
Ldata$day <- rep(1:7, each=24, length.out=1536)
Upvotes: 4