Dear R Helpers,

I'm struggling with a data preparation problem. I feel that it is a quite
easy task but I don't get it done. I hope you can help me with that.

I have a data frame looking like this:

ID <- c(1,1,1,2,2,3,3,3,3)
T <- c(1,2,3,1,4,3,5,6,8)
x <- rep(1,9)
df <- data.frame(ID,T,x)

>df
ID T x
1 1 1
1 2 1
1 3 1
2 1 1
2 4 1
3 3 1
3 5 1
3 6 1
3 8 1

I want to manipulate the x column in a way that for each customer (ID) at
the minimum of T the x value is set to zero. The result should look like
this:

ID T x x_new
1 1 1     0
1 2 1     1
1 3 1     1
2 1 1     0
2 4 1     1
3 3 1     0
3 5 1     1
3 6 1     1
3 8 1     1

I already tried the aggregate() and apply() function, but I don't get the
result I'm looking for. I would glad if you could help me out.

Best regards,
Carlos

	[[alternative HTML version deleted]]

