[R] little manipulation on data frame

Spencer Graves spencer.graves at pdf.com
Fri Jun 6 18:20:11 CEST 2003


I don't completely understand what you want, but might the following help?

 > cumsum(1:11)
  [1]  1  3  6 10 15 21 28 36 45 55 66
 > which(cumsum(1:11)>9)
[1]  4  5  6  7  8  9 10 11
 > which(cumsum(1:11)>9)[1]
[1] 4

hth.  spencer graves

N Dey wrote:
> Dear all,
> 
> I have data like 3 coulmns and many rows. Each entry
> is less than 10.
> 
> Example
> 	x	y	z
> 1	5	3	2	
> 2	3	7	8
> 3	8	9	5
> 4	5	4	6
> --------------------------
> ---------------------------
> 
> I have to sum entries of each coulmn (seperately) till
> it be 10. This i have to start for each row. And I
> want to assign no. of rows needed including that row
> too(it to be 10 or 10+, the moment it exceeds 10, i
> need to stop and count the no. of rows)in additional
> coulmns say N1 (corresponding to coulmn x), N2 (y) and
> N3 (z).
> 
> 
> I want my new table like
> 
> 	x	y	z	N1	N2	N3 
> 1	5	3	2	3	2	2
> 2	3	7	8	2	2	2	
> 3	8	9	5	2	2	2
> 4	5	4	6	depends upon next row
> 
> 
> If anybody knows it, please help me.
> 
> Thanking you.
> 
> Best regards,
> N. Dey.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list