Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Another option:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading