Create a sequence along the whole dataset increasing by certain number in R

How to create a new variable in the dataframe with a sequence increasing by 0.002, starting at 0 and running until the end of the dataset. I was attempting with:

dataset$seq = seq(0, length(dataset), by = 0.002)
dataset$seq = seq(0, nrow(dataset), by = 0.002)

But both throw an error about wrong lengths. Thanks for your help.

>Solution :

Another option:

dataset$seq <- seq(0, by = 0.002, length.out = nrow(dataset))

Leave a Reply