0

I have 10 million+ data points which look like:

Identifier Times                Data
6597104    2015-05-01 04:08:05  0.15512575543732

In order to study these I want to add a Period (1, 2,...) column so the oldest row with the 6597104 identifier is period 1 and the second oldest is period 2 etc. However the times come irregularly so I can't just make it a time series object.

Does anyone know how to do this? Thanks in advance

Ben Lenz
  • 1
  • 1
  • 3
    Welcome to SO; Please help us to help you with a piece of you data. just `dput` a little sample of your data, and for next times read [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) about how to create a reproducible example. – SabDeM Jul 15 '15 at 20:25
  • Thanks, brand new to R and trying to figure out dput now. – Ben Lenz Jul 15 '15 at 20:47
  • Here is an example of how to sample from a data set, which uses the build in `iris` dataset. `zz <- iris[sample(1:nrow(iris), 10), ]`, just `dput(zz)` copy and paste here. – SabDeM Jul 15 '15 at 20:52
  • do multiple identifies fall in the same period? – Rorschach Jul 15 '15 at 20:54
  • SabDeM: Thanks, but for some reason it's filling up the whole gui rather than just giving me 10 nongkrong: At the moment no but I'm gonna new data in a couple days that might change that. – Ben Lenz Jul 15 '15 at 21:10

1 Answers1

0

Let's call your data frame data

First sort it using

data <- data[sort(data$Times,decreasing=TRUE),]

Then add a new column called Period

for i in 1:nrow(data){
data$Period[i] <- paste("Period",i,sep=" ")
}
Buzz Lightyear
  • 824
  • 1
  • 7
  • 18
  • Thanks, for the quick response but I think what you described will only give an ascending period to each row chronologically, but what I want different identifiers to have different periods. – Ben Lenz Jul 15 '15 at 20:52