No, this is not a homework. Thank you so much!


On Wed, Mar 12, 2014 at 10:39 AM, Kehl Dániel <kehld@ktk.pte.hu> wrote:

> Hi,
>
> is this homework?
> Try
> d <- c(8,7,5,5,3,3,2,1,1,1)
>
> r <- rep(1,length(d))
>
> for (i in 2:length(d)) {
>
>   if (d[i] != d[i-1]) {
>     r[i]=r[i-1]+1;
>   }
>   else {
>     r[i] = r[i-1];
>   }
> }
>
> Although I am sure there are better solutions!
>
> HTH
> daniel
>
> ________________________________________
> Feladó: r-help-bounces@r-project.org [r-help-bounces@r-project.org] ;
> meghatalmaz&#243;: T Bal [studenttbal@gmail.com]
> Küldve: 2014. március 12. 10:13
> To: r-help@r-project.org
> Tárgy: [R] Assign numbers in R
>
> Hi,
> I have the following numbers:
>
> d <- c(8,7,5,5,3,3,2,1,1,1)
>
> I want to convert these into the following numbers:
>
> r:
> 1,2,3,3,4,4,5,6,6,6
>
> So if two numbers are different increment it if they are same then assign
> the same number:
>
> r <- NULL
>
> for (i in 1:length(d)) {
>
>  if (d[i] != d[i+1]) {
>   r[i] =i+1;
>  }
>  else {
>   r[i] = i;
>  }
>  }
>
> But this is not correct. How can I solve this problem? or how can I solve
> it in a different way? Thanks a lot!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]


