Skip to content
Prev 327234 / 398502 Next

Calculate interaction for a big dataframe

Hi,
You could try:
?cumsum(c(1,abs(diff(as.numeric(factor(v1))))))
# [1] 1 1 1 2 2 3 3 3 3 4
A.K.




----- Original Message -----
From: Arnaud Michel <michel.arnaud at cirad.fr>
To: PIKAL Petr <petr.pikal at precheza.cz>
Cc: R help <r-help at r-project.org>
Sent: Monday, July 22, 2013 11:41 AM
Subject: Re: [R] Calculate interaction for a big dataframe

Thank you Petr
paste is better than interaction for long vectors
But now a new problem/question is appeared.
Now, I would like transform the vector
v1 <- c(
"4162.France", "4162.France", "4162.France",
"4162.Mali", "4162.Mali",
"4162.France", "4162.France", "4162.France", "4162.France",
"4162.Mali")
into a vector V2 with the same length but with number which are creasing
v2 <- c(1,? ?  1,? ? 1,
2, 2,
3, 3,3,3,
4))

Any idea (function) ?
Regards


Le 22/07/2013 14:45, PIKAL Petr a ?crit :