[R] to calculate c(rep(1, 43), rep(2,43),...., rep(10,43))

2014-12-11 Thread Arnaud Michel

Hello
I would like to find an elegant way of calculating
c(rep(1, 43), rep(2,43),, rep(10,43))

Any idea ?
Thank you

--
Michel ARNAUD
DGDRD-Drh - TA 174/04
tel : 04.67.61.75.38
port: 06.47.43.55.31

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] outputs of a function

2014-12-04 Thread Arnaud Michel
Hello

I have a function named FctModele13 in which
1) I calculate a dataframe named Total and
2) I used ggplot2.
I have the following problem. I cannot produce simultaneously

  * the graphic by ggplot2
  * the dataframe

My simplified code is the following one :


TT - FctModele13(ListePlusde50ans, PourcentSexeCsp, NbAn=10)
FctModele - function(ListePlusde50ans, PourcentSexeCsp, NbAn)
{
# calculate Total
.
.
Total - data.frame()
###
# plot by ggplot
library(ggplot2)
ggplot(.) +
..
axis.title.y = element_text(size = 8)) +
labs(title=Title)

Total
}



Any idea ?

-- 
Michel ARNAUD
CIRAD Montpellier
tel : 04.67.61.75.38
port: 06.47.43.55.31


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] outputs of a function

2014-12-04 Thread Arnaud Michel

Thank you Jeff and Mark for your help
Michel

Le 04/12/2014 15:09, Jeff Newmiller a écrit :

This is a poor approach from a usability perspective... I suggest you create 
two separate functions rather than one.

However, you seem to be missing a crucial point in the use of ggplot, which also applies 
to lattice graphics. These functions actually don't produce output at all... they produce 
grid graphics objects that produce graphic output when printed. 
Interactively, this printing step is done automatically for you, but inside functions 
that does not happen. So, you can wrap your ggplot expression in a print function call to 
have your function produce the graphic output as a side effect.

print( ggplot(.) +
..
axis.title.y = element_text(size = 8)) +
labs(title=Title) )

One of the things that is nice about grid graphics is that you can modify the 
object before you print it. For example, if you make a basic scatterplot 
function for your data, you can tack on things like labels or extra lines to 
aid your explanation about what is in the data just as you print it. Then you 
can also print it later with different notations or none at all. Having a 
separate graph-generating function that just returns the grid object for you to 
print or modify as you wish can be quite useful later.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On December 4, 2014 2:09:12 AM PST, Arnaud Michel michel.arn...@cirad.fr 
wrote:

Hello

I have a function named FctModele13 in which
1) I calculate a dataframe named Total and
2) I used ggplot2.
I have the following problem. I cannot produce simultaneously

  * the graphic by ggplot2
  * the dataframe

My simplified code is the following one :


TT - FctModele13(ListePlusde50ans, PourcentSexeCsp, NbAn=10)
FctModele - function(ListePlusde50ans, PourcentSexeCsp, NbAn)
{
# calculate Total
.
.
Total - data.frame()
###
# plot by ggplot
library(ggplot2)
ggplot(.) +
..
axis.title.y = element_text(size = 8)) +
labs(title=Title)

Total
}



Any idea ?





--
Michel ARNAUD
DGDRD-Drh - TA 174/04
tel : 04.67.61.75.38
port: 06.47.43.55.31

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] To calculate the month number between 2 dates

2014-11-07 Thread Arnaud Michel

Hello
Can one calculate the month number between two dates
D1 - 01/01/2007  and D2 - 01/04/2009 ?
Thank you


--
Michel ARNAUD
Cirad

__
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.


Re: [R] To build a new Df from 2 Df

2014-10-15 Thread Arnaud Michel

Thank you David
Now, the problem is to list all the combinations which verify the 
condition III (ie every Rapporteur has to have more or less the same 
number of demandeur)

Have you any idea ?
Michel




Le 14/10/2014 13:18, david.kaeth...@dlr.de a écrit :

Hello,

here's a draft of a solution. I hope it's not overly complicated.

# find all possible combinations
combi - expand.grid(Dem$Nom, Rap$Nom); names(combi) - c(Dem, Rap)

# we need the corresponding departments and units
combi$DemDep - apply(combi, 1, function(x) Dem$Departement[x[1] == Dem$Nom])
combi$DemUni - apply(combi, 1, function(x) Dem$Unite[x[1] == Dem$Nom])
combi$RapDep - apply(combi, 1, function(x) Rap$Departement[x[2] == Rap$Nom])
combi$RapUni - apply(combi, 1, function(x) Rap$Unite[x[2] == Rap$Nom])

# we exclude the combinations that we don't want
dep - combi[combi$DemDep != combi$RapDep, c(Dem, Rap)]
dep$id - as.numeric(dep$Rap)
uni - combi[combi$DemUni != combi$RapUni, c(Dem, Rap)]
uni$id - as.numeric(uni$Rap)

# preliminary result
resDep - reshape(dep,
 timevar = id,
 idvar = Dem,
 direction = wide
)

resUni - reshape(uni,
   timevar = id,
   idvar = Dem,
   direction = wide
)

In resDep and resUni you find the results for Rapporteur1 and Rapporteur2. NAs 
indicate where conditions did not match. For Rap1/Rap2 you can now choose any 
column from resDep and resUni that is not NA for that specific Demandeur. I 
wasn't exactly sure about your third condition, so I'll leave that to you. But 
with the complete possible matches, you have a more general solution.

Btw, you can construct data.frames just like this:

Dem - data.frame(
   Nom = c(John, Jim, Julie, Charles, Michel, Emma, Sandra, Elodie, Thierry, Albert, Jean, Francois, Pierre, 
Cyril, Damien, Jean-Michel, Vincent, Daniel, Yvan, Catherine),
   Departement = c(D, A, A, C, D, B, D, B, C, D, B, B, B, A, C, D, B, 
A, D, D),
   Unite = c(Unite8, Unite4, Unite4, Unite7, Unite9, Unite1, Unite6, Unite5, Unite7, Unite3, Unite2, Unite6, Unite8, 
Unite8, Unite3, Unite8, Unite9, Unite7, Unite9, Unite5)
)

-dk

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im 
Auftrag von Arnaud Michel
Gesendet: Dienstag, 14. Oktober 2014 10:46
An: r-help@r-project.org
Betreff: [R] To build a new Df from 2 Df

Hello

I have 2 df Dem and Rap.
I would want to build all the df (dfnew) by associating these two df (Dem and 
Rap) in the following way :

For each value of Dem$Nom (dfnew$Demandeur), I associate 2 different values of 
Rap$Nom (dfnew$Rapporteur1 and dfnew$Rapporteur2) in such a way

   * for each dfnew$Demandeur, dfnew$Rapporteur1 does not have the same
 value for Departement as Dem$Departement
   * for each dfnew$Demandeur, dfnew$Rapporteur2 does not have the same
 value for Unite as Dem$Unite
   * the value of table(dfnew$Rapporteur1) and the value of
 table(dfnew$Rapporteur2) must be balanced and not too different
 (Accepted differences : 1)

table(dfnew$Rapporteur1)
Rapporteur01 Rapporteur02 Rapporteur03 Rapporteur04 Rapporteur05
 4   4 4  4
4

Thanks for your help
Michel

   Dem - structure(list(Nom = c(John, Jim, Julie, Charles, Michel, Emma, Sandra, Elodie, Thierry, Albert, Jean, Francois, Pierre, Cyril, Damien, Jean-Michel, Vincent, Daniel, Yvan, Catherine), Departement = c(D, A, A, C, D, B, D, B, C, D, B, B, B, A, C, D, B, 
A, D, D), Unite = c(Unite8, Unite4, Unite4, Unite7, Unite9, Unite1, Unite6, Unite5, Unite7, Unite3, Unite2, Unite6, Unite8, Unite8, Unite3, Unite8, Unite9, Unite7, Unite9, Unite5)), .Names = c(Nom, Departement, Unite
), row.names = c(NA, -20L), class = data.frame)

Rap - structure(list(Nom = c(Rapporteur01, Rapporteur02, Rapporteur03, Rapporteur04, Rapporteur05), Departement = c(C, D, C, C, D), Unite = 
c(Unite10, Unite6, Unite5, Unite5, Unite4)), .Names = c(Nom, Departement, Unite), row.names = c(NA, -5L), class = data.frame)

dfnew - structure(list(Demandeur = structure(c(13L, 12L, 14L, 3L, 15L, 8L, 17L, 7L, 18L, 1L, 10L, 9L, 16L, 4L, 5L, 11L, 19L, 6L, 20L, 2L), .Label = c(Albert, Catherine, Charles, Cyril, Damien, Daniel, Elodie, Emma, Francois, Jean, Jean-Michel, Jim, John, Julie, 
Michel, Pierre, Sandra, Thierry, Vincent, Yvan), class = factor), Rapporteur1 = structure(c(3L, 1L, 3L, 5L, 1L, 5L, 1L, 2L, 5L, 4L, 2L, 4L, 2L, 3L, 5L, 4L, 4L, 2L, 3L, 1L), .Label = c(Rapporteur01, Rapporteur02, Rapporteur03, Rapporteur04, Rapporteur05), class = factor), Rapporteur2 = 
structure(c(1L, 3L, 4L, 4L, 2L, 4L, 5L, 1L, 2L, 3L, 3L, 3L, 5L, 5L, 1L, 1L, 2L, 5L, 4L, 2L), .Label = c(Rapporteur01, Rapporteur02, Rapporteur03, Rapporteur04, Rapporteur05), class = factor)), .Names = c(Demandeur, Rapporteur1, Rapporteur2), row.names = c(NA, -20L), class =
data.frame)


--
Michel ARNAUD
Cirad Montpellier


[[alternative HTML version deleted

[R] To build a new Df from 2 Df

2014-10-14 Thread Arnaud Michel
Hello

I have 2 df Dem and Rap.
I would want to build all the df (dfnew) by associating these two df 
(Dem and Rap) in the following way :

For each value of Dem$Nom (dfnew$Demandeur), I associate 2 different 
values of Rap$Nom (dfnew$Rapporteur1 and dfnew$Rapporteur2) in such a way

  * for each dfnew$Demandeur, dfnew$Rapporteur1 does not have the same
value for Departement as Dem$Departement
  * for each dfnew$Demandeur, dfnew$Rapporteur2 does not have the same
value for Unite as Dem$Unite
  * the value of table(dfnew$Rapporteur1) and the value of
table(dfnew$Rapporteur2) must be balanced and not too different
(Accepted differences : 1)

table(dfnew$Rapporteur1)
Rapporteur01 Rapporteur02 Rapporteur03 Rapporteur04 Rapporteur05
4   4 4  4   
   4

Thanks for your help
Michel

  Dem - structure(list(Nom = c(John, Jim, Julie, Charles, 
Michel,
Emma, Sandra, Elodie, Thierry, Albert, Jean, Francois,
Pierre, Cyril, Damien, Jean-Michel, Vincent, Daniel,
Yvan, Catherine), Departement = c(D, A, A, C, D,
B, D, B, C, D, B, B, B, A, C, D, B, A,
D, D), Unite = c(Unite8, Unite4, Unite4, Unite7,
Unite9, Unite1, Unite6, Unite5, Unite7, Unite3, Unite2,
Unite6, Unite8, Unite8, Unite3, Unite8, Unite9, Unite7,
Unite9, Unite5)), .Names = c(Nom, Departement, Unite
), row.names = c(NA, -20L), class = data.frame)

Rap - structure(list(Nom = c(Rapporteur01, Rapporteur02, 
Rapporteur03,
Rapporteur04, Rapporteur05), Departement = c(C, D, C,
C, D), Unite = c(Unite10, Unite6, Unite5, Unite5,
Unite4)), .Names = c(Nom, Departement, Unite), row.names = c(NA,
-5L), class = data.frame)

dfnew - structure(list(Demandeur = structure(c(13L, 12L, 14L, 3L, 15L,
8L, 17L, 7L, 18L, 1L, 10L, 9L, 16L, 4L, 5L, 11L, 19L, 6L, 20L,
2L), .Label = c(Albert, Catherine, Charles, Cyril, Damien,
Daniel, Elodie, Emma, Francois, Jean, Jean-Michel,
Jim, John, Julie, Michel, Pierre, Sandra, Thierry,
Vincent, Yvan), class = factor), Rapporteur1 = structure(c(3L,
1L, 3L, 5L, 1L, 5L, 1L, 2L, 5L, 4L, 2L, 4L, 2L, 3L, 5L, 4L, 4L,
2L, 3L, 1L), .Label = c(Rapporteur01, Rapporteur02, Rapporteur03,
Rapporteur04, Rapporteur05), class = factor), Rapporteur2 = 
structure(c(1L,
3L, 4L, 4L, 2L, 4L, 5L, 1L, 2L, 3L, 3L, 3L, 5L, 5L, 1L, 1L, 2L,
5L, 4L, 2L), .Label = c(Rapporteur01, Rapporteur02, Rapporteur03,
Rapporteur04, Rapporteur05), class = factor)), .Names = 
c(Demandeur,
Rapporteur1, Rapporteur2), row.names = c(NA, -20L), class = 
data.frame)


-- 
Michel ARNAUD
Cirad Montpellier


[[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.


[R] To Add a variable from Df1 to Df2 which have a same common variable

2014-09-19 Thread Arnaud Michel

Hello
I have the two dataframes Df1 and Df2 which have the common variable 
AgeSexeCadNCad
I would like to add the new variable Df2$Pourcent which correspond at 
the value of Df1$AgeSexeCadNCad.

Thank you for your help.
Michel

Df1 - structure(list(AgeSexeCadNCad = structure(1:36, .Label = 
c(60-Femme-Cadre,

60-Femme-Non Cadre, 60-Homme-Cadre, 60-Homme-Non Cadre,
61-Femme-Cadre, 61-Femme-Non Cadre, 61-Homme-Cadre, 61-Homme-Non 
Cadre,
62-Femme-Cadre, 62-Femme-Non Cadre, 62-Homme-Cadre, 62-Homme-Non 
Cadre,
63-Femme-Cadre, 63-Femme-Non Cadre, 63-Homme-Cadre, 63-Homme-Non 
Cadre,
64-Femme-Cadre, 64-Femme-Non Cadre, 64-Homme-Cadre, 64-Homme-Non 
Cadre,
65-Femme-Cadre, 65-Femme-Non Cadre, 65-Homme-Cadre, 65-Homme-Non 
Cadre,
66-Femme-Cadre, 66-Femme-Non Cadre, 66-Homme-Cadre, 66-Homme-Non 
Cadre,
67-Femme-Cadre, 67-Femme-Non Cadre, 67-Homme-Cadre, 67-Homme-Non 
Cadre,
68-Femme-Cadre, 68-Femme-Non Cadre, 68-Homme-Cadre, 68-Homme-Non 
Cadre

), class = factor), Pourcent = c(0.157849638357511, 0.157849638357511,
0.0562149664637629, 0.419279916358023, 0.180720729132166, 
0.180720729132166,

0.092720981524322, 0.272158156192425, 0.145668562090518, 0.145668562090518,
0.101319648271574, 0.159207521192769, 0.0997898095090109, 
0.0997898095090109,
0.110753346057845, 0.0193586234067497, 0.0795236495990374, 
0.0795236495990374,
0.18014205547984, 0.00968491550180694, 0.0750838561972432, 
0.0750838561972432,
0.237072554382218, 0.0650665901855087, 0.0587392216209752, 
0.0587392216209752,
0.126427289344211, 0.00961707878904615, 0.0409034699088397, 
0.0409034699088397,

0.0537806700836756, 3.11172383820597e-05, 0.0285360029533433,
0.0285360029533433, 0.0220930854712636, 2.20203747900568e-09)), .Names = 
c(AgeSexeCadNCad,

Pourcent), row.names = c(28L, 19L, 10L, 1L, 29L, 20L, 11L,
2L, 30L, 21L, 12L, 3L, 31L, 22L, 13L, 4L, 32L, 23L, 14L, 5L,
33L, 24L, 15L, 6L, 34L, 25L, 16L, 7L, 35L, 26L, 17L, 8L, 36L,
27L, 18L, 9L), class = data.frame)

Df2 - structure(list(Matricule = c(410, 453, 501, 544, 653, 765, 833,
851, 927, 1050, 1074, 1278, 1379, 1428, 359, 379, 408, 417, 424,
426, 483, 490, 528, 538, 567, 596, 603, 604, 647, 675, 677, 681,
735, 743, 787, 817, 823, 896, 917, 1071, 1144, 1157, 1823, 2497,
2868, 3556, 3614, 3632, 3646, 3656, 3660, 4162, 4503, 4711, 5531,
330, 447, 467, 546, 627, 637, 780, 892, 1487, 1492, 3324, 4873,
409, 415, 441, 579, 619, 697, 716, 719, 728, 737, 807, 832, 989,
1299, 1320, 1352, 1427, 1484, 1548, 2447, 2914, 2929, 2941, 3524,
3527, 3631, 4324, 400, 572, 1095, 1097, 1105, 2966, 392, 418,
440, 457, 466, 472, 488, 491, 506, 533, 543, 547, 552, 553, 920,
1034, 1179, 1454, 1485, 1540, 3620, 4672, 13899, 342, 1089, 1208,
1234, 2153, 3545, 253, 504, 529, 558, 578, 745, 933, 935, 2099,
16785, 356, 460, 634, 959, 1429, 1591, 1720, 3602, 3644, 322,
361, 404, 430, 525, 706, 804, 1010, 1012, 1108, 1185, 1294, 2264,
3567, 3633, 4990, 264, 298, 352, 388, 503, 508, 691, 1509, 2192,
3060, 3683, 877, 1130, 1963, 188, 327, 331, 363, 437, 445, 462,
723, 1259, 1381, 3617, 427, 1402, 3624, 141, 256, 308, 377, 414,
640, 157, 560), AgeSexeCadNCad = c(60-Femme-Non Cadre, 60-Femme-Non 
Cadre,

60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 62-Femme-Non Cadre,

Re: [R] To Add a variable from Df1 to Df2 which have a same common variable

2014-09-19 Thread Arnaud Michel

Thank you to Marc Schwartz, Rui Barrada and Sarah Goslee
Michel
Le 19/09/2014 19:46, Marc Schwartz a écrit :

On Sep 19, 2014, at 12:15 PM, Arnaud Michel michel.arn...@cirad.fr wrote:


Hello
I have the two dataframes Df1 and Df2 which have the common variable 
AgeSexeCadNCad
I would like to add the new variable Df2$Pourcent which correspond at the value 
of Df1$AgeSexeCadNCad.
Thank you for your help.
Michel

Df1 - structure(list(AgeSexeCadNCad = structure(1:36, .Label = 
c(60-Femme-Cadre,
60-Femme-Non Cadre, 60-Homme-Cadre, 60-Homme-Non Cadre,
61-Femme-Cadre, 61-Femme-Non Cadre, 61-Homme-Cadre, 61-Homme-Non Cadre,
62-Femme-Cadre, 62-Femme-Non Cadre, 62-Homme-Cadre, 62-Homme-Non Cadre,
63-Femme-Cadre, 63-Femme-Non Cadre, 63-Homme-Cadre, 63-Homme-Non Cadre,
64-Femme-Cadre, 64-Femme-Non Cadre, 64-Homme-Cadre, 64-Homme-Non Cadre,
65-Femme-Cadre, 65-Femme-Non Cadre, 65-Homme-Cadre, 65-Homme-Non Cadre,
66-Femme-Cadre, 66-Femme-Non Cadre, 66-Homme-Cadre, 66-Homme-Non Cadre,
67-Femme-Cadre, 67-Femme-Non Cadre, 67-Homme-Cadre, 67-Homme-Non Cadre,
68-Femme-Cadre, 68-Femme-Non Cadre, 68-Homme-Cadre, 68-Homme-Non Cadre
), class = factor), Pourcent = c(0.157849638357511, 0.157849638357511,
0.0562149664637629, 0.419279916358023, 0.180720729132166, 0.180720729132166,
0.092720981524322, 0.272158156192425, 0.145668562090518, 0.145668562090518,
0.101319648271574, 0.159207521192769, 0.0997898095090109, 0.0997898095090109,
0.110753346057845, 0.0193586234067497, 0.0795236495990374, 0.0795236495990374,
0.18014205547984, 0.00968491550180694, 0.0750838561972432, 0.0750838561972432,
0.237072554382218, 0.0650665901855087, 0.0587392216209752, 0.0587392216209752,
0.126427289344211, 0.00961707878904615, 0.0409034699088397, 0.0409034699088397,
0.0537806700836756, 3.11172383820597e-05, 0.0285360029533433,
0.0285360029533433, 0.0220930854712636, 2.20203747900568e-09)), .Names = 
c(AgeSexeCadNCad,
Pourcent), row.names = c(28L, 19L, 10L, 1L, 29L, 20L, 11L,
2L, 30L, 21L, 12L, 3L, 31L, 22L, 13L, 4L, 32L, 23L, 14L, 5L,
33L, 24L, 15L, 6L, 34L, 25L, 16L, 7L, 35L, 26L, 17L, 8L, 36L,
27L, 18L, 9L), class = data.frame)

Df2 - structure(list(Matricule = c(410, 453, 501, 544, 653, 765, 833,
851, 927, 1050, 1074, 1278, 1379, 1428, 359, 379, 408, 417, 424,
426, 483, 490, 528, 538, 567, 596, 603, 604, 647, 675, 677, 681,
735, 743, 787, 817, 823, 896, 917, 1071, 1144, 1157, 1823, 2497,
2868, 3556, 3614, 3632, 3646, 3656, 3660, 4162, 4503, 4711, 5531,
330, 447, 467, 546, 627, 637, 780, 892, 1487, 1492, 3324, 4873,
409, 415, 441, 579, 619, 697, 716, 719, 728, 737, 807, 832, 989,
1299, 1320, 1352, 1427, 1484, 1548, 2447, 2914, 2929, 2941, 3524,
3527, 3631, 4324, 400, 572, 1095, 1097, 1105, 2966, 392, 418,
440, 457, 466, 472, 488, 491, 506, 533, 543, 547, 552, 553, 920,
1034, 1179, 1454, 1485, 1540, 3620, 4672, 13899, 342, 1089, 1208,
1234, 2153, 3545, 253, 504, 529, 558, 578, 745, 933, 935, 2099,
16785, 356, 460, 634, 959, 1429, 1591, 1720, 3602, 3644, 322,
361, 404, 430, 525, 706, 804, 1010, 1012, 1108, 1185, 1294, 2264,
3567, 3633, 4990, 264, 298, 352, 388, 503, 508, 691, 1509, 2192,
3060, 3683, 877, 1130, 1963, 188, 327, 331, 363, 437, 445, 462,
723, 1259, 1381, 3617, 427, 1402, 3624, 141, 256, 308, 377, 414,
640, 157, 560), AgeSexeCadNCad = c(60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Femme-Non Cadre, 60-Femme-Non Cadre, 60-Femme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 60-Homme-Non Cadre,
60-Homme-Non Cadre, 60-Homme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Femme-Non Cadre,
61-Femme-Non Cadre, 61-Femme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre, 61-Homme-Non Cadre, 61-Homme-Non Cadre,
61-Homme-Non Cadre

[R] Plotrix and twoord.plot with date on x-axe

2014-07-26 Thread Arnaud Michel

Hello

With package plotrix and  twoord.plot function, I would like to put the 
labels of the ticks values of x-axe which are date (
c(2006 Jan, 2007 Jan, 2008 Jan, 2009 Jan, 2010 Jan, 2011 
Jan, 2012 Jan) with if possible, the angle of labels and x-axe = 40

Any idea ?

Thank you for your help

My dataframe is
TT -
structure(list(x1 = structure(c(1L, 8L, 15L, 22L, 29L, 36L, 43L,
50L, 57L, 64L, 71L, 77L, 2L, 9L, 16L, 23L, 30L, 37L, 44L, 51L,
58L, 65L, 3L, 10L, 17L, 24L, 31L, 38L, 45L, 52L, 59L, 66L, 72L,
78L, 4L, 11L, 18L, 25L, 32L, 39L, 46L, 53L, 60L, 67L, 73L, 79L,
5L, 12L, 19L, 26L, 33L, 40L, 47L, 54L, 61L, 68L, 74L, 80L, 6L,
13L, 20L, 27L, 34L, 41L, 48L, 55L, 62L, 69L, 75L, 81L, 7L, 14L,
21L, 28L, 35L, 42L, 49L, 56L, 63L, 70L, 76L, 82L), .Label = c(01/01/2006,
01/01/2007, 01/01/2008, 01/01/2009, 01/01/2010, 01/01/2011,
01/01/2012, 01/02/2006, 01/02/2007, 01/02/2008, 01/02/2009,
01/02/2010, 01/02/2011, 01/02/2012, 01/03/2006, 01/03/2007,
01/03/2008, 01/03/2009, 01/03/2010, 01/03/2011, 01/03/2012,
01/04/2006, 01/04/2007, 01/04/2008, 01/04/2009, 01/04/2010,
01/04/2011, 01/04/2012, 01/05/2006, 01/05/2007, 01/05/2008,
01/05/2009, 01/05/2010, 01/05/2011, 01/05/2012, 01/06/2006,
01/06/2007, 01/06/2008, 01/06/2009, 01/06/2010, 01/06/2011,
01/06/2012, 01/07/2006, 01/07/2007, 01/07/2008, 01/07/2009,
01/07/2010, 01/07/2011, 01/07/2012, 01/08/2006, 01/08/2007,
01/08/2008, 01/08/2009, 01/08/2010, 01/08/2011, 01/08/2012,
01/09/2006, 01/09/2007, 01/09/2008, 01/09/2009, 01/09/2010,
01/09/2011, 01/09/2012, 01/10/2006, 01/10/2007, 01/10/2008,
01/10/2009, 01/10/2010, 01/10/2011, 01/10/2012, 01/11/2006,
01/11/2008, 01/11/2009, 01/11/2010, 01/11/2011, 01/11/2012,
01/12/2006, 01/12/2008, 01/12/2009, 01/12/2010, 01/12/2011,
01/12/2012), class = factor), y1 = c(2.592356082, 2.345800476,
0.583585821, 5.475129414, 5.475129414, 3.718656646, 3.089374967,
2.301938832, 2.937799758, 2.194943003, 2.54038668, NA, 1.644678741,
1.449029225, 0.956848412, 0.859023655, 0.987578146, 0.843738536,
1.247265662, 1.284694265, 0.980520409, 0.835670652, 0.566612694,
0.401453666, 0.439134806, 1.15846577, 0.687179049, 0.494573266,
0.96702963, 0.504182954, 1.03521455, 0.41886541, 0.401638417,
0.143972524, 0.84561927, 0.551221244, 0.916415951, 1.455635055,
2.866544524, 1.709780054, 1.846827755, 1.451262182, 0.807575275,
1.590211883, 1.542348196, 0.937123964, 1.399639685, 1.091996771,
1.404915044, 1.816230935, 1.468899879, 1.34414673, 1.480941894,
1.325698257, 1.462174427, 1.294317244, 1.348639226, 0.743242205,
1.326535615, 1.288495608, 0.825648931, 0.520199099, 0.631660841,
0.4838471, 0.514975576, 0.644832626, 0.789323515, 0.380945025,
0.386553999, 0.342014493, 0.351664055, 0.188006956, 0.238740258,
0.223667802, 0.063293682, 0.254889318, 0.324071093, 0.323446397,
0.291533728, 0.152346111, 0.429059919, 0.237783277), y2 = c(3.59979021,
3.760067114, 3.668671329, 4.08590604, 3.772684564, 3.833825503,
3.770872483, 3.801879195, 3.776442953, 3.807248322, 3.623087248,
3.85, 3.723986014, 3.67041958, 3.594405594, 3.595244755, 3.457832168,
3.582684564, 3.580839161, 3.555804196, 3.409060403, 3.39885906,
2.707342657, 2.483986014, 2.548881119, 2.797202797, 2.66034965,
2.792447552, 2.597482517, 2.243426573, 2.300629371, 2.323356643,
2.057832168, 2.142167832, 2.829300699, 2.45013986, 2.418531469,
2.77027972, 3.384335664, 3.32048951, 3.297762238, 3.008531469,
2.645034965, 2.965104895, 2.826853147, 2.747342657, 3.053986014,
3.327132867, 2.845874126, 2.961748252, 3.104335664, 3.076153846,
3.259090909, 3.08013986, 3.022727273, 3.016433566, 3.261468531,
2.942237762, 3.217972028, 2.904685315, 2.674755245, 2.436783217,
2.466853147, 2.557272727, 2.696853147, 3.308111888, 3.121468531,
3.144195804, 3.017132867, 3.069160839, 2.985384615, 2.661258741,
2.681188811, 2.746433566, 2.797202797, 2.666713287, 2.474335664,
2.769230769, 2.623356643, 2.764195804, 2.658391608, 2.665594406
), date = structure(1:82, .Label = c(2006-01-01, 2006-02-01,
2006-03-01, 2006-04-01, 2006-05-01, 2006-06-01, 2006-07-01,
2006-08-01, 2006-09-01, 2006-10-01, 2006-11-01, 2006-12-01,
2007-01-01, 2007-02-01, 2007-03-01, 2007-04-01, 2007-05-01,
2007-06-01, 2007-07-01, 2007-08-01, 2007-09-01, 2007-10-01,
2008-01-01, 2008-02-01, 2008-03-01, 2008-04-01, 2008-05-01,
2008-06-01, 2008-07-01, 2008-08-01, 2008-09-01, 2008-10-01,
2008-11-01, 2008-12-01, 2009-01-01, 2009-02-01, 2009-03-01,
2009-04-01, 2009-05-01, 2009-06-01, 2009-07-01, 2009-08-01,
2009-09-01, 2009-10-01, 2009-11-01, 2009-12-01, 2010-01-01,
2010-02-01, 2010-03-01, 2010-04-01, 2010-05-01, 2010-06-01,
2010-07-01, 2010-08-01, 2010-09-01, 2010-10-01, 2010-11-01,
2010-12-01, 2011-01-01, 2011-02-01, 2011-03-01, 2011-04-01,
2011-05-01, 2011-06-01, 2011-07-01, 2011-08-01, 2011-09-01,
2011-10-01, 2011-11-01, 2011-12-01, 2012-01-01, 2012-02-01,
2012-03-01, 2012-04-01, 2012-05-01, 2012-06-01, 2012-07-01,
2012-08-01, 2012-09-01, 2012-10-01, 2012-11-01, 2012-12-01
), class = factor), datepos = structure(c(2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 

Re: [R] Plotrix and twoord.plot with date on x-axe

2014-07-26 Thread Arnaud Michel

Perfect Jim, It's fine !
Thank you
Michel

Le 26/07/2014 12:16, Jim Lemon a écrit :

On Sat, 26 Jul 2014 09:36:49 AM Arnaud Michel wrote:

Hello

With package plotrix and  twoord.plot function, I would like to put the
labels of the ticks values of x-axe which are date (
c(2006 Jan, 2007 Jan, 2008 Jan, 2009 Jan, 2010 Jan, 2011
Jan, 2012 Jan) with if possible, the angle of labels and x-axe = 40
Any idea ?

Thank you for your help

My dataframe is
TT -
structure(list(x1 = structure(c(1L, 8L, 15L, 22L, 29L, 36L, 43L,
50L, 57L, 64L, 71L, 77L, 2L, 9L, 16L, 23L, 30L, 37L, 44L, 51L,
58L, 65L, 3L, 10L, 17L, 24L, 31L, 38L, 45L, 52L, 59L, 66L, 72L,
78L, 4L, 11L, 18L, 25L, 32L, 39L, 46L, 53L, 60L, 67L, 73L, 79L,
5L, 12L, 19L, 26L, 33L, 40L, 47L, 54L, 61L, 68L, 74L, 80L, 6L,
13L, 20L, 27L, 34L, 41L, 48L, 55L, 62L, 69L, 75L, 81L, 7L, 14L,
21L, 28L, 35L, 42L, 49L, 56L, 63L, 70L, 76L, 82L), .Label =

c(01/01/2006,

01/01/2007, 01/01/2008, 01/01/2009, 01/01/2010,

01/01/2011,

01/01/2012, 01/02/2006, 01/02/2007, 01/02/2008,

01/02/2009,

01/02/2010, 01/02/2011, 01/02/2012, 01/03/2006,

01/03/2007,

01/03/2008, 01/03/2009, 01/03/2010, 01/03/2011,

01/03/2012,

01/04/2006, 01/04/2007, 01/04/2008, 01/04/2009,

01/04/2010,

01/04/2011, 01/04/2012, 01/05/2006, 01/05/2007,

01/05/2008,

01/05/2009, 01/05/2010, 01/05/2011, 01/05/2012,

01/06/2006,

01/06/2007, 01/06/2008, 01/06/2009, 01/06/2010,

01/06/2011,

01/06/2012, 01/07/2006, 01/07/2007, 01/07/2008,

01/07/2009,

01/07/2010, 01/07/2011, 01/07/2012, 01/08/2006,

01/08/2007,

01/08/2008, 01/08/2009, 01/08/2010, 01/08/2011,

01/08/2012,

01/09/2006, 01/09/2007, 01/09/2008, 01/09/2009,

01/09/2010,

01/09/2011, 01/09/2012, 01/10/2006, 01/10/2007,

01/10/2008,

01/10/2009, 01/10/2010, 01/10/2011, 01/10/2012,

01/11/2006,

01/11/2008, 01/11/2009, 01/11/2010, 01/11/2011,

01/11/2012,

01/12/2006, 01/12/2008, 01/12/2009, 01/12/2010,

01/12/2011,

01/12/2012), class = factor), y1 = c(2.592356082, 2.345800476,
0.583585821, 5.475129414, 5.475129414, 3.718656646,

3.089374967,

2.301938832, 2.937799758, 2.194943003, 2.54038668, NA,

1.644678741,

1.449029225, 0.956848412, 0.859023655, 0.987578146,

0.843738536,

1.247265662, 1.284694265, 0.980520409, 0.835670652,

0.566612694,

0.401453666, 0.439134806, 1.15846577, 0.687179049,

0.494573266,

0.96702963, 0.504182954, 1.03521455, 0.41886541, 0.401638417,
0.143972524, 0.84561927, 0.551221244, 0.916415951,

1.455635055,

2.866544524, 1.709780054, 1.846827755, 1.451262182,

0.807575275,

1.590211883, 1.542348196, 0.937123964, 1.399639685,

1.091996771,

1.404915044, 1.816230935, 1.468899879, 1.34414673,

1.480941894,

1.325698257, 1.462174427, 1.294317244, 1.348639226,

0.743242205,

1.326535615, 1.288495608, 0.825648931, 0.520199099,

0.631660841,

0.4838471, 0.514975576, 0.644832626, 0.789323515,

0.380945025,

0.386553999, 0.342014493, 0.351664055, 0.188006956,

0.238740258,

0.223667802, 0.063293682, 0.254889318, 0.324071093,

0.323446397,

0.291533728, 0.152346111, 0.429059919, 0.237783277), y2 =

c(3.59979021,

3.760067114, 3.668671329, 4.08590604, 3.772684564,

3.833825503,

3.770872483, 3.801879195, 3.776442953, 3.807248322,

3.623087248,

3.85, 3.723986014, 3.67041958, 3.594405594, 3.595244755,

3.457832168,

3.582684564, 3.580839161, 3.555804196, 3.409060403,

3.39885906,

2.707342657, 2.483986014, 2.548881119, 2.797202797,

2.66034965,

2.792447552, 2.597482517, 2.243426573, 2.300629371,

2.323356643,

2.057832168, 2.142167832, 2.829300699, 2.45013986,

2.418531469,

2.77027972, 3.384335664, 3.32048951, 3.297762238,

3.008531469,

2.645034965, 2.965104895, 2.826853147, 2.747342657,

3.053986014,

3.327132867, 2.845874126, 2.961748252, 3.104335664,

3.076153846,

3.259090909, 3.08013986, 3.022727273, 3.016433566,

3.261468531,

2.942237762, 3.217972028, 2.904685315, 2.674755245,

2.436783217,

2.466853147, 2.557272727, 2.696853147, 3.308111888,

3.121468531,

3.144195804, 3.017132867, 3.069160839, 2.985384615,

2.661258741,

2.681188811, 2.746433566, 2.797202797, 2.666713287,

2.474335664,

2.769230769, 2.623356643, 2.764195804, 2.658391608,

2.665594406

), date = structure(1:82, .Label = c(2006-01-01, 2006-02-01,
2006-03-01, 2006-04-01, 2006-05-01, 2006-06-01,

2006-07-01,

2006-08-01, 2006-09-01, 2006-10-01, 2006-11-01,

2006-12-01,

2007-01-01, 2007-02-01, 2007-03-01, 2007-04-01,

2007-05-01,

2007-06-01, 2007-07-01, 2007-08-01, 2007-09-01,

2007-10-01,

2008-01-01, 2008-02-01, 2008-03-01, 2008-04-01,

2008-05-01,

2008-06-01, 2008-07-01, 2008-08-01, 2008-09-01,

2008-10-01,

2008-11-01, 2008-12-01, 2009-01-01, 2009-02-01,

2009-03-01,

2009-04-01, 2009-05-01, 2009-06-01, 2009-07-01,

2009-08-01,

2009-09-01, 2009-10-01, 2009-11-01, 2009-12-01,

2010-01-01,

2010-02-01, 2010-03-01, 2010-04-01, 2010-05-01,

2010-06-01,

2010-07-01, 2010-08-01, 2010-09-01, 2010-10-01,

2010-11-01,

2010-12-01, 2011-01-01, 2011-02-01, 2011-03-01,

2011-04-01,

2011-05-01, 2011-06-01, 2011-07-01, 2011-08-01,

2011-09-01,

2011-10-01, 2011-11

Re: [R] Plotrix and twoord.plot with date on x-axe

2014-07-26 Thread Arnaud Michel

Perfect Jim, It's fine !
Michel

Le 26/07/2014 12:16, Jim Lemon a écrit :

On Sat, 26 Jul 2014 09:36:49 AM Arnaud Michel wrote:

Hello

With package plotrix and  twoord.plot function, I would like to put the
labels of the ticks values of x-axe which are date (
c(2006 Jan, 2007 Jan, 2008 Jan, 2009 Jan, 2010 Jan, 2011
Jan, 2012 Jan) with if possible, the angle of labels and x-axe = 40
Any idea ?

Thank you for your help

My dataframe is
TT -
structure(list(x1 = structure(c(1L, 8L, 15L, 22L, 29L, 36L, 43L,
50L, 57L, 64L, 71L, 77L, 2L, 9L, 16L, 23L, 30L, 37L, 44L, 51L,
58L, 65L, 3L, 10L, 17L, 24L, 31L, 38L, 45L, 52L, 59L, 66L, 72L,
78L, 4L, 11L, 18L, 25L, 32L, 39L, 46L, 53L, 60L, 67L, 73L, 79L,
5L, 12L, 19L, 26L, 33L, 40L, 47L, 54L, 61L, 68L, 74L, 80L, 6L,
13L, 20L, 27L, 34L, 41L, 48L, 55L, 62L, 69L, 75L, 81L, 7L, 14L,
21L, 28L, 35L, 42L, 49L, 56L, 63L, 70L, 76L, 82L), .Label =

c(01/01/2006,

01/01/2007, 01/01/2008, 01/01/2009, 01/01/2010,

01/01/2011,

01/01/2012, 01/02/2006, 01/02/2007, 01/02/2008,

01/02/2009,

01/02/2010, 01/02/2011, 01/02/2012, 01/03/2006,

01/03/2007,

01/03/2008, 01/03/2009, 01/03/2010, 01/03/2011,

01/03/2012,

01/04/2006, 01/04/2007, 01/04/2008, 01/04/2009,

01/04/2010,

01/04/2011, 01/04/2012, 01/05/2006, 01/05/2007,

01/05/2008,

01/05/2009, 01/05/2010, 01/05/2011, 01/05/2012,

01/06/2006,

01/06/2007, 01/06/2008, 01/06/2009, 01/06/2010,

01/06/2011,

01/06/2012, 01/07/2006, 01/07/2007, 01/07/2008,

01/07/2009,

01/07/2010, 01/07/2011, 01/07/2012, 01/08/2006,

01/08/2007,

01/08/2008, 01/08/2009, 01/08/2010, 01/08/2011,

01/08/2012,

01/09/2006, 01/09/2007, 01/09/2008, 01/09/2009,

01/09/2010,

01/09/2011, 01/09/2012, 01/10/2006, 01/10/2007,

01/10/2008,

01/10/2009, 01/10/2010, 01/10/2011, 01/10/2012,

01/11/2006,

01/11/2008, 01/11/2009, 01/11/2010, 01/11/2011,

01/11/2012,

01/12/2006, 01/12/2008, 01/12/2009, 01/12/2010,

01/12/2011,

01/12/2012), class = factor), y1 = c(2.592356082, 2.345800476,
0.583585821, 5.475129414, 5.475129414, 3.718656646,

3.089374967,

2.301938832, 2.937799758, 2.194943003, 2.54038668, NA,

1.644678741,

1.449029225, 0.956848412, 0.859023655, 0.987578146,

0.843738536,

1.247265662, 1.284694265, 0.980520409, 0.835670652,

0.566612694,

0.401453666, 0.439134806, 1.15846577, 0.687179049,

0.494573266,

0.96702963, 0.504182954, 1.03521455, 0.41886541, 0.401638417,
0.143972524, 0.84561927, 0.551221244, 0.916415951,

1.455635055,

2.866544524, 1.709780054, 1.846827755, 1.451262182,

0.807575275,

1.590211883, 1.542348196, 0.937123964, 1.399639685,

1.091996771,

1.404915044, 1.816230935, 1.468899879, 1.34414673,

1.480941894,

1.325698257, 1.462174427, 1.294317244, 1.348639226,

0.743242205,

1.326535615, 1.288495608, 0.825648931, 0.520199099,

0.631660841,

0.4838471, 0.514975576, 0.644832626, 0.789323515,

0.380945025,

0.386553999, 0.342014493, 0.351664055, 0.188006956,

0.238740258,

0.223667802, 0.063293682, 0.254889318, 0.324071093,

0.323446397,

0.291533728, 0.152346111, 0.429059919, 0.237783277), y2 =

c(3.59979021,

3.760067114, 3.668671329, 4.08590604, 3.772684564,

3.833825503,

3.770872483, 3.801879195, 3.776442953, 3.807248322,

3.623087248,

3.85, 3.723986014, 3.67041958, 3.594405594, 3.595244755,

3.457832168,

3.582684564, 3.580839161, 3.555804196, 3.409060403,

3.39885906,

2.707342657, 2.483986014, 2.548881119, 2.797202797,

2.66034965,

2.792447552, 2.597482517, 2.243426573, 2.300629371,

2.323356643,

2.057832168, 2.142167832, 2.829300699, 2.45013986,

2.418531469,

2.77027972, 3.384335664, 3.32048951, 3.297762238,

3.008531469,

2.645034965, 2.965104895, 2.826853147, 2.747342657,

3.053986014,

3.327132867, 2.845874126, 2.961748252, 3.104335664,

3.076153846,

3.259090909, 3.08013986, 3.022727273, 3.016433566,

3.261468531,

2.942237762, 3.217972028, 2.904685315, 2.674755245,

2.436783217,

2.466853147, 2.557272727, 2.696853147, 3.308111888,

3.121468531,

3.144195804, 3.017132867, 3.069160839, 2.985384615,

2.661258741,

2.681188811, 2.746433566, 2.797202797, 2.666713287,

2.474335664,

2.769230769, 2.623356643, 2.764195804, 2.658391608,

2.665594406

), date = structure(1:82, .Label = c(2006-01-01, 2006-02-01,
2006-03-01, 2006-04-01, 2006-05-01, 2006-06-01,

2006-07-01,

2006-08-01, 2006-09-01, 2006-10-01, 2006-11-01,

2006-12-01,

2007-01-01, 2007-02-01, 2007-03-01, 2007-04-01,

2007-05-01,

2007-06-01, 2007-07-01, 2007-08-01, 2007-09-01,

2007-10-01,

2008-01-01, 2008-02-01, 2008-03-01, 2008-04-01,

2008-05-01,

2008-06-01, 2008-07-01, 2008-08-01, 2008-09-01,

2008-10-01,

2008-11-01, 2008-12-01, 2009-01-01, 2009-02-01,

2009-03-01,

2009-04-01, 2009-05-01, 2009-06-01, 2009-07-01,

2009-08-01,

2009-09-01, 2009-10-01, 2009-11-01, 2009-12-01,

2010-01-01,

2010-02-01, 2010-03-01, 2010-04-01, 2010-05-01,

2010-06-01,

2010-07-01, 2010-08-01, 2010-09-01, 2010-10-01,

2010-11-01,

2010-12-01, 2011-01-01, 2011-02-01, 2011-03-01,

2011-04-01,

2011-05-01, 2011-06-01, 2011-07-01, 2011-08-01,

2011-09-01,

2011-10-01, 2011-11-01, 2011-12

[R] To map population of European countries from Eurostat

2014-02-06 Thread Arnaud Michel

Hello
I would like to map the population of the European countries in 2011.
I am using the spatial shapefiles of Europe published by EUROSTAT.
I applyed the script below of Markus Kainubut but I had a problem with 
the map.


Any ideas ?
Thanks for your help

#
# Importing the data
library(SmarterPoland)
df - getEurostatRaw(kod = tps1)

# rename 1ere variable
names(df) - c(xx, 2002:2013)

# new variable df$unit et df$geo.time
df$unit - lapply(strsplit(as.character(df$xx), ,), [, 1)
df$geo.time - lapply(strsplit(as.character(df$xx), ,), [, 2)

# file df.l
df.l - melt(data = df, id.vars = geo.time, measure.vars = c(2002, 
2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 
2013))


df.l$geo.time - unlist(df.l$geo.time)  # unlist the geo.time variable

# Load the shapefile GISCO, subset it to NUTS2-level
# and merge the Eurostat
# attribute data with it into single SpatialPolygonDataFrame

Filetodownload - 
http://epp.eurostat.ec.europa.eu/cache/GISCO/geodatafiles/NUTS_2010_60M_SH.zip;

download.file(Filetodownload, destfile = NUTS_2010_60M_SH.zip)
rm(Filetodownload)

# Unzip NUTS_2010_60M_SH.zip to SpatialPolygonsDataFrame
unzip(NUTS_2010_60M_SH.zip)

library(rgdal)
# Lecture du fichier
map - readOGR(dsn = ./NUTS_2010_60M_SH/data, layer = NUTS_RG_60M_2010)
# OGR data source with driver: ESRI Shapefile
# Source: ./NUTS_2010_60M_SH/data, layer: NUTS_RG_60M_2010
# with 1920 features and 4 fields
# Feature type: wkbPolygon with 2 dimensions

names(map)
#[1] NUTS_IDSTAT_LEVL_ SHAPE_Leng SHAPE_Area

# as the data is at NUTS2-level, we subset the
# spatialpolygondataframe
map_nuts2 - subset(map, STAT_LEVL_ = 2)

# dim show how many regions are in the spatialpolygondataframe
dim(map_nuts2)
## [1] 467   4

# dim show how many regions are in the data.frame
dim(df)
## [1] 43  15


# Spatial dataframe has 467 rows and attribute data 43.  We need to make
# attribute data to have similar number of rows
NUTS_ID - as.character(map_nuts2$NUTS_ID)
VarX - rep(empty, 467)
dat - data.frame(NUTS_ID, VarX)

# then we shall merge this with Eurostat data.frame
dat2 - merge(dat, df, by.x = NUTS_ID, by.y = geo.time, all.x = TRUE)

## merge this manipulated attribute data with the spatialpolygondataframe
## there are still duplicates in the data, remove them
dat2$dup - duplicated(dat2$NUTS_ID)
dat3 - subset(dat2, dup == FALSE)

## rownames
row.names(dat3) - dat3$NUTS_ID
row.names(map_nuts2) - as.character(map_nuts2$NUTS_ID)

## order data
dat3 - dat3[order(row.names(dat3)), ]
map_nuts2 - map_nuts2[order(row.names(map_nuts2)), ]

## join
library(maptools)
shape - spCbind(map_nuts2, dat3)

##
# Munging the shapefile into data.frame and ready for ggplot-plotting

## fortify spatialpolygondataframe into data.frame
library(ggplot2)
library(rgeos)
shape$id - rownames(shape@data)
map.points - fortify(shape, region = id)
map.df - merge(map.points, shape, by = id)

###
# Only year 2011
# As we want to plot map faceted by years from 2003 to 2011 we have to
# melt it into long format
map.df - map.df[, -c(15:23,25,26)]
library(reshape2)

map.df.l - melt(data = map.df, id.vars = c(id, long, lat, 
group), measure.vars = c(X2011))


# year variable (variable) is class string and type X20xx.  Lets remove
# the X and convert it to numerical

library(stringr)
map.df.l$variable - str_replace_all(map.df.l$variable, X, )
map.df.l$variable - factor(map.df.l$variable)
map.df.l$variable - 
as.numeric(levels(map.df.l$variable))[map.df.l$variable]


# And finally the plot using ggplot2
#Map shows proportion of materially deprived households at the NUTS2 level.
#Grey color indicates missing data.


library(ggplot2)

ggplot(map.df.l, aes(long,lat,group=group)) +
geom_polygon(aes(fill = value)) +
geom_polygon(data = map.df.l, aes(long,lat),
fill=NA, color = white,
size=0.1) + # white borders
coord_map(project=orthographic, xlim=c(-22,34), ylim=c(35,70)) + # proj
labs(title = Cartographie) +
theme_minimal()

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] to modify a dataframe

2014-01-01 Thread Arnaud Michel

Dear All,

From the dataframe df1

df1 -
structure(list(Nom = structure(1:9, .Label = c(A1, A2, A3,
B1, B2, C1, C2, C3, C4), class = factor), Pays1 = c(1,
1, 0, 0, 1, 0, 0, 0, 0), Pays2 = c(0, 0, 0, 1, 1, 0, 1, 0, 1),
Pays3 = c(0, 0, 0, 0, 1, 0, 0, 0, 0), Pays4 = c(1, 0, 0,
0, 0, 0, 1, 0, 1), Pays5 = c(1, 1, 0, 0, 0, 0, 0, 0, 0)), .Names = c(Nom,
Pays1, Pays2, Pays3, Pays4, Pays5), row.names = c(1L,
3L, 4L, 2L, 5L, 6L, 7L, 8L, 9L), class = data.frame)


I look for a way to build the new dataframe df2
 
df2 -

structure(list(Nom = structure(1:9, .Label = c(A1, A2, A3,
B1, B2, C1, C2, C3, C4), class = factor), Pays1 = c(1,
1, 1, 1, 1, 0, 0, 0, 0), Pays2 = c(0, 0, 0, 1, 1, 1, 1, 1, 1),
Pays3 = c(0, 0, 0, 1, 1, 0, 0, 0, 0), Pays4 = c(1, 1, 1,
0, 0, 1, 1, 1, 1), Pays5 = c(1, 1, 1, 0, 0, 0, 0, 0, 0)), .Names = c(Nom,
Pays1, Pays2, Pays3, Pays4, Pays5), row.names = c(NA,
-9L), class = data.frame)

The purpose is to transform df1 it df2 by giving for every group of lines A, B 
and C the value 1 if there is at least a value equal to 1 or a value 0 if there 
is no value equal to 1

Thanks for your helps

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] to replace the for loop

2013-12-13 Thread Arnaud Michel

Hello

I would like to replace the for loop this below

T - as.matrix(T)
for(i in 1: nrow(TEMP)){
for(j in 1: nrow(TEMP)){if (i = j) T[i, j] - 0 }}

I don't find the function in the doc.
Thanks in advance for your help.

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] To transform a vector of qualitatives values into a dataframe of quantitatives values

2013-12-11 Thread Arnaud Michel

Hi

From the vector
X - c(A, A, B, C, B, A, C)

I would like to build the Dataframe :
data.frame( A=c(1,1,0,0,0,1,0), B=c(0,0,1,0,1,0,0), C=c(0,0,0,1,0,0,1))

Any ideas ?


--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] To transform a vector

2013-12-08 Thread Arnaud Michel

Dear R Users

I have the vector
X - c( 6 , 4 ,12 , 3)

I would like to build a new vector by to transform it into
Y - c(rep(X[1], X[1]), rep(X[2], X[2]), rep(X[3], X[3]), rep(X[4], X[4]))

Have you a more elegant answer ?

PS : Sorry for this basic question

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] To transform a vector

2013-12-08 Thread Arnaud Michel

Thank you
Michel
Le 09/12/2013 08:14, Berend Hasselman a écrit :

On 09-12-2013, at 08:04, Arnaud Michel michel.arn...@cirad.fr wrote:


Dear R Users

I have the vector
X - c( 6 , 4 ,12 , 3)

I would like to build a new vector by to transform it into
Y - c(rep(X[1], X[1]), rep(X[2], X[2]), rep(X[3], X[3]), rep(X[4], X[4]))

Have you a more elegant answer ?


Have a good read of ?rep.

Try this:

rep(X,times=X)

Berend





--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] To transform an adjacency matrix

2013-11-20 Thread Arnaud Michel
Hi
I have the following problem
I would like to build, from a matrix filled with 0 and with 1, a matrix 
or a data.frame which contains, in every line, the number of the line 
and the number of the column of the matrix for which the value is equal 
to 1.
Exemple :

dput(m)
structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,
0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L))

Result

1 5
2 3
2 4
4 1
4 3

Thank you for your help

-- 
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31


[[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.


Re: [R] To transform an adjacency matrix

2013-11-20 Thread Arnaud Michel

Thank you Pascal
Its fine
Michel
Le 20/11/2013 11:55, Pascal Oettli a écrit :

Hello,

One approach is:

m - structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L))
out - which(m==1, arr.ind=TRUE)
out[order(out[,1]),]

Regards,
Pascal

On 20 November 2013 19:28, Arnaud Michel michel.arn...@cirad.fr wrote:

Hi
I have the following problem
I would like to build, from a matrix filled with 0 and with 1, a matrix
or a data.frame which contains, in every line, the number of the line
and the number of the column of the matrix for which the value is equal
to 1.
Exemple :

dput(m)
structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,
0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L))

Result

1 5
2 3
2 4
4 1
4 3

Thank you for your help

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31


 [[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.






--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] To transform an adjacency matrix

2013-11-20 Thread Arnaud Michel

Thank you also for your help
Michel
Le 20/11/2013 19:04, Dennis Murphy a écrit :

Hi:

which(m == 1L, arr.ind = TRUE)

Dennis

On Wed, Nov 20, 2013 at 2:28 AM, Arnaud Michel michel.arn...@cirad.fr wrote:

Hi
I have the following problem
I would like to build, from a matrix filled with 0 and with 1, a matrix
or a data.frame which contains, in every line, the number of the line
and the number of the column of the matrix for which the value is equal
to 1.
Exemple :

dput(m)
structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,
0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L))

Result

1 5
2 3
2 4
4 1
4 3

Thank you for your help

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31


 [[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.





--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] add points on an existant ggplot from another dataframe

2013-10-14 Thread Arnaud Michel

Hello
I had draw the results of PCA (Principal Components Analysis) (1)
Is it possible to put on this graphic the 75% ellipse confidence of each 
sex calculated by dataEllipse (library(car)) ?


My code is
1) PCA data frame with 169 rows and 2 columns
library(ggplot2)
p - ggplot(PCA, aes(x=F1, y=F2 ))
p + geom_point(aes(colour = Sexe, shape = Sexe), size=3) +
geom_hline(yintercept = 0) +
geom_vline(xintercept = 0) +
labs(title = ACP,
x = Facteur 1, y = Facteur 2,fill = Sexe) +
theme(legend.position = c(0.95,0.95),
legend.background = element_rect(colour = black))

2) library(car)
XH - dataEllipse(
X1[ACP$Sexe==H],
X2[ACP$Sexe==H],
levels=0.75, lty=2, add=TRUE, plot.points=FALSE, center.cex=0, col=4)

XF - dataEllipse(
X1[ACP$Sexe==F],
X2[ACP$Sexe==F],
levels=0.75, lty=2, add=TRUE, plot.points=FALSE, center.cex=0, col=2)

XH and XF are two matrix with 2 columns and 52 rows
Thank you for your help

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] ggplot2 : to change the title of legend

2013-10-11 Thread Arnaud Michel

Hello
I don't arrive to change the title of the legend
My code is :
library(ggplot2)
ma - max(General$AgeChangCat) ; mi - min(General$AgeChangCat)
Test$Recrutement - factor(Test$CadNonCadRecrut)
p -
ggplot(Test, aes(x=factor(Cat1), y=AgeChangCat )) +
ylim(mi,ma) +
geom_point() +
geom_boxplot(aes(fill = Recrutement)) +
labs(title = Age, x=catégorie, y=Age) +
theme(legend.position = c(0.1,0.9), legend.background = 
element_rect(colour = black))

p

any idea ?

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] ggplot2 : to change the title of legend

2013-10-11 Thread Arnaud Michel

OK It is right
Thank you Petr
Michel
Le 11/10/2013 14:58, PIKAL Petr a écrit :

Hi

I usually use scale

something like
scale_fill_discrete(name = Fancy Title)
shall do the trick

Regards
Petr



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of Arnaud Michel
Sent: Friday, October 11, 2013 11:02 AM
To: R help
Subject: [R] ggplot2 : to change the title of legend

Hello
I don't arrive to change the title of the legend My code is :
library(ggplot2)
ma - max(General$AgeChangCat) ; mi - min(General$AgeChangCat)
Test$Recrutement - factor(Test$CadNonCadRecrut) p - ggplot(Test,
aes(x=factor(Cat1), y=AgeChangCat )) +
ylim(mi,ma) +
geom_point() +
geom_boxplot(aes(fill = Recrutement)) +
labs(title = Age, x=catégorie, y=Age) + theme(legend.position =
c(0.1,0.9), legend.background = element_rect(colour = black)) p

any idea ?

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.




--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] delete some lines of a dataframe

2013-09-18 Thread Arnaud Michel

Merci Arun
Michel
Le 17/09/2013 22:41, arun a écrit :


Hi Arnaud,
You could also try:
indx- Df1$Mat[-1]==Df1$Mat[-nrow(Df1)]
indx1-c(indx,FALSE)
indx2-c(FALSE,indx)

Df1[indx1,]
  Df1[indx2,]
A.K.




From: arun smartpink...@yahoo.com
To: Arnaud Michel michel.arn...@cirad.fr
Cc: R help r-help@r-project.org
Sent: Tuesday, September 17, 2013 4:21 PM
Subject: Re: [R] delete some lines of a dataframe


Hi Arnaud,

In that case:

Try:
Df1[duplicated(Df1$Mat),]
  Df1[duplicated(Df1$Mat,fromLast=TRUE),]

#or


A.K.


- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: arun smartpink...@yahoo.com
Cc: R help r-help@r-project.org
Sent: Tuesday, September 17, 2013 4:00 PM
Subject: Re: [R] delete some lines of a dataframe

Thank you Arun
but the values of other columns may be different !!!
Michel
Le 17/09/2013 20:56, arun a écrit :

Hi,
Try:
Df1[duplicated(Df1),]
Df1[duplicated(Df1,fromLast=TRUE),]
A.K.



- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Tuesday, September 17, 2013 2:14 PM
Subject: [R] delete some lines of a dataframe

Hi

I have a dataframe Df1
dput(Df1)
structure(list(Mat = c(141, 141, 157, 157, 188, 188, 232, 232,
253, 253, 253, 254, 254, 254, 254, 256, 256, 264, 264), Prenom = c(Pierre,
Pierre, Jean-Claude, Jean-Claude, Jean-Louis, Jean-Louis,
Philippe, Philippe, Christophe, Christophe, Christophe,
Dominique, Dominique, Dominique, Dominique, Pierre-Luc,
Pierre-Luc, Alain, Alain), Sexe = c(Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin),
   DateNais = c(23/08/1946, 23/08/1946, 11/08/1945, 11/08/1945,
   09/04/1948, 09/04/1948, 01/05/1946, 01/05/1946, 11/02/1951,
   11/02/1951, 11/02/1951, 21/10/1949, 21/10/1949, 21/10/1949,
   21/10/1949, 25/06/1946, 25/06/1946, 13/03/1949, 13/03/1949
   )), .Names = c(Mat, Prenom, Sexe, DateNais), row.names = c(207,
208, 232, 233, 288, 289, 373, 374, 412, 413,
414, 415, 416, 417, 418, 420, 421, 436, 437
), class = data.frame)

I want to extract of Df1 2 other dataframes :
1) delete the first line for each values of Mat
  Mat  Prenom Sexe   DateNais
208 141  Pierre Masculin 23/08/1946
233 157 Jean-Claude Masculin 11/08/1945
289 188  Jean-Louis Masculin 09/04/1948
374 232Philippe Masculin 01/05/1946
413 253  Christophe Masculin 11/02/1951
414 253  Christophe Masculin 11/02/1951
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
418 254   Dominique Masculin 21/10/1949
421 256  Pierre-Luc Masculin 25/06/1946
437 264   Alain Masculin 13/03/1949

2) delete the last line for each values of Mat
   Mat  Prenom Sexe   DateNais
207 141  Pierre Masculin 23/08/1946
232 157 Jean-Claude Masculin 11/08/1945
288 188  Jean-Louis Masculin 09/04/1948
373 232Philippe Masculin 01/05/1946
412 253  Christophe Masculin 11/02/1951
413 253  Christophe Masculin 11/02/1951
415 254   Dominique Masculin 21/10/1949
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
420 256  Pierre-Luc Masculin 25/06/1946
436 264   Alain Masculin 13/03/1949

Any ideas ?


-- Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.




--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] delete some lines of a dataframe

2013-09-17 Thread Arnaud Michel

Hi

I have a dataframe Df1
dput(Df1)
structure(list(Mat = c(141, 141, 157, 157, 188, 188, 232, 232,
253, 253, 253, 254, 254, 254, 254, 256, 256, 264, 264), Prenom = 
c(Pierre,

Pierre, Jean-Claude, Jean-Claude, Jean-Louis, Jean-Louis,
Philippe, Philippe, Christophe, Christophe, Christophe,
Dominique, Dominique, Dominique, Dominique, Pierre-Luc,
Pierre-Luc, Alain, Alain), Sexe = c(Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin),
DateNais = c(23/08/1946, 23/08/1946, 11/08/1945, 11/08/1945,
09/04/1948, 09/04/1948, 01/05/1946, 01/05/1946, 11/02/1951,
11/02/1951, 11/02/1951, 21/10/1949, 21/10/1949, 21/10/1949,
21/10/1949, 25/06/1946, 25/06/1946, 13/03/1949, 13/03/1949
)), .Names = c(Mat, Prenom, Sexe, DateNais), row.names = 
c(207,

208, 232, 233, 288, 289, 373, 374, 412, 413,
414, 415, 416, 417, 418, 420, 421, 436, 437
), class = data.frame)

I want to extract of Df1 2 other dataframes :
1) delete the first line for each values of Mat
   Mat  Prenom Sexe   DateNais
208 141  Pierre Masculin 23/08/1946
233 157 Jean-Claude Masculin 11/08/1945
289 188  Jean-Louis Masculin 09/04/1948
374 232Philippe Masculin 01/05/1946
413 253  Christophe Masculin 11/02/1951
414 253  Christophe Masculin 11/02/1951
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
418 254   Dominique Masculin 21/10/1949
421 256  Pierre-Luc Masculin 25/06/1946
437 264   Alain Masculin 13/03/1949

2) delete the last line for each values of Mat
Mat  Prenom Sexe   DateNais
207 141  Pierre Masculin 23/08/1946
232 157 Jean-Claude Masculin 11/08/1945
288 188  Jean-Louis Masculin 09/04/1948
373 232Philippe Masculin 01/05/1946
412 253  Christophe Masculin 11/02/1951
413 253  Christophe Masculin 11/02/1951
415 254   Dominique Masculin 21/10/1949
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
420 256  Pierre-Luc Masculin 25/06/1946
436 264   Alain Masculin 13/03/1949

Any ideas ?


--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] delete some lines of a dataframe

2013-09-17 Thread Arnaud Michel

Thank you Arun
but the values of other columns may be different !!!
Michel
Le 17/09/2013 20:56, arun a écrit :

Hi,
Try:
Df1[duplicated(Df1),]
  Df1[duplicated(Df1,fromLast=TRUE),]
A.K.



- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Tuesday, September 17, 2013 2:14 PM
Subject: [R] delete some lines of a dataframe

Hi

I have a dataframe Df1
dput(Df1)
structure(list(Mat = c(141, 141, 157, 157, 188, 188, 232, 232,
253, 253, 253, 254, 254, 254, 254, 256, 256, 264, 264), Prenom = c(Pierre,
Pierre, Jean-Claude, Jean-Claude, Jean-Louis, Jean-Louis,
Philippe, Philippe, Christophe, Christophe, Christophe,
Dominique, Dominique, Dominique, Dominique, Pierre-Luc,
Pierre-Luc, Alain, Alain), Sexe = c(Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin),
 DateNais = c(23/08/1946, 23/08/1946, 11/08/1945, 11/08/1945,
 09/04/1948, 09/04/1948, 01/05/1946, 01/05/1946, 11/02/1951,
 11/02/1951, 11/02/1951, 21/10/1949, 21/10/1949, 21/10/1949,
 21/10/1949, 25/06/1946, 25/06/1946, 13/03/1949, 13/03/1949
 )), .Names = c(Mat, Prenom, Sexe, DateNais), row.names = c(207,
208, 232, 233, 288, 289, 373, 374, 412, 413,
414, 415, 416, 417, 418, 420, 421, 436, 437
), class = data.frame)

I want to extract of Df1 2 other dataframes :
1) delete the first line for each values of Mat
Mat  Prenom Sexe   DateNais
208 141  Pierre Masculin 23/08/1946
233 157 Jean-Claude Masculin 11/08/1945
289 188  Jean-Louis Masculin 09/04/1948
374 232Philippe Masculin 01/05/1946
413 253  Christophe Masculin 11/02/1951
414 253  Christophe Masculin 11/02/1951
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
418 254   Dominique Masculin 21/10/1949
421 256  Pierre-Luc Masculin 25/06/1946
437 264   Alain Masculin 13/03/1949

2) delete the last line for each values of Mat
 Mat  Prenom Sexe   DateNais
207 141  Pierre Masculin 23/08/1946
232 157 Jean-Claude Masculin 11/08/1945
288 188  Jean-Louis Masculin 09/04/1948
373 232Philippe Masculin 01/05/1946
412 253  Christophe Masculin 11/02/1951
413 253  Christophe Masculin 11/02/1951
415 254   Dominique Masculin 21/10/1949
416 254   Dominique Masculin 21/10/1949
417 254   Dominique Masculin 21/10/1949
420 256  Pierre-Luc Masculin 25/06/1946
436 264   Alain Masculin 13/03/1949

Any ideas ?


-- Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.




--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] Change the color of the line inside of the function lines

2013-09-16 Thread Arnaud Michel

Hi

I have the following problem :
I have 3 vectors xx, yy, zz :
xx -  c(5479,  6209,  6940,  7670,  8766,  9496, 10227, 11048, 11778, 
12509, 13239, 13970,

14700, 15340, 15948)
yy - c( 267, 275, 281, 287, 296, 306, 316, 325, 334, 351, 365, 377, 
389, 419, 419)

zz - c( 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6)
I would like a line wich join the points (xx, yy) with stair steps (as 
type = s)

plot(xx, yy, type=n)
lines(xx, yy, type =s)
but I want to change the color according to the value of zz (exemple : 
col = 1 if zz =3 ; col =2 if zz= 4 ;  col =3 if zz= 5 ;  col =4 if zz= 6)

Thank you for your help

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] Change the color of the line inside of the function lines

2013-09-16 Thread Arnaud Michel
Hi Tsjerk
Thank you but the color always remains black !
I would want that the color changes on the same graph (color = 3 on the 
4 first steps, col = 4 on 5 following steps

Michel

Le 16/09/2013 09:01, Tsjerk Wassenaar a écrit :
 Hi Michel,

 lines(xx,yy,col=zz-2,type=s)

 If you use a color vector, say cols, then you can also do

 lines(xx,yy,col=cols[zz-2],type=s)

 Hope it helps,

 Tsjerk


 On Mon, Sep 16, 2013 at 8:42 AM, Arnaud Michel michel.arn...@cirad.fr 
 mailto:michel.arn...@cirad.fr wrote:

 Hi

 I have the following problem :
 I have 3 vectors xx, yy, zz :
 xx -  c(5479,  6209,  6940,  7670,  8766,  9496, 10227, 11048,
 11778, 12509, 13239, 13970,
 14700, 15340, 15948)
 yy - c( 267, 275, 281, 287, 296, 306, 316, 325, 334, 351, 365,
 377, 389, 419, 419)
 zz - c( 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6)
 I would like a line wich join the points (xx, yy) with stair steps
 (as type = s)
 plot(xx, yy, type=n)
 lines(xx, yy, type =s)
 but I want to change the color according to the value of zz
 (exemple : col = 1 if zz =3 ; col =2 if zz= 4 ;  col =3 if zz= 5 ;
  col =4 if zz= 6)
 Thank you for your help

 -- 
 Michel ARNAUD
 Chargé de mission auprès du DRH
 DGDRD-Drh - TA 174/04
 Av Agropolis 34398 Montpellier cedex 5
 tel : 04.67.61.75.38
 fax : 04.67.61.57.87
 port: 06.47.43.55.31

 __
 R-help@r-project.org mailto: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.




 -- 
 Tsjerk A. Wassenaar, Ph.D.


-- 
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31


[[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.


Re: [R] Change the color of the line inside of the function lines

2013-09-16 Thread Arnaud Michel

Thanks Pascal and Tsjerk
Michel
Le 16/09/2013 09:42, Pascal Oettli a écrit :

Hi,

Maybe the following might help you:

 s - seq(length(xx)-1)
 plot(xx, yy, type=n)
 segments(xx[s], yy[s], xx[s+1], yy[s], col=zz, lwd=2)
 segments(xx[s+1], yy[s], xx[s+1], yy[s+1], col='grey')

Regards,
Pascal


On 16/09/2013 15:42, Arnaud Michel wrote:

Hi

I have the following problem :
I have 3 vectors xx, yy, zz :
xx -  c(5479,  6209,  6940,  7670,  8766,  9496, 10227, 11048, 11778,
12509, 13239, 13970,
14700, 15340, 15948)
yy - c( 267, 275, 281, 287, 296, 306, 316, 325, 334, 351, 365, 377,
389, 419, 419)
zz - c( 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6)
I would like a line wich join the points (xx, yy) with stair steps (as
type = s)
plot(xx, yy, type=n)
lines(xx, yy, type =s)
but I want to change the color according to the value of zz (exemple :
col = 1 if zz =3 ; col =2 if zz= 4 ;  col =3 if zz= 5 ;  col =4 if 
zz= 6)

Thank you for your help





--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] to avoid a do loop

2013-09-08 Thread Arnaud Michel

Hello
I have a large dataframe  (nrow=55000).
This below df1 an extract of the original dataframe

dput(df1)
structure(list(Cat = c(6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4,
4, 8, 8, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, 6, 7, 7,
7, 7, 7), Ech = c(8, 9, 10, 11, 12, 12, 13, 13, 11, 12, 13, 14,
14, 14, 9, 10, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 11, 11,
4, 5, 6, 7, 8, 8, 8, 9, 9, 8, 9, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5,
5, 1, 2, 3, 4, 5, 6, 6, 6, 7, 7, 7, 5, 6, 7, 8, 9, 9, 10, 10,
11, 11, 11, 11, 11, 11, 15, 5, 6, 7, 7, 8, 8, 8, 8, 9, 9, 13,
13, 14, 15, 15, 15, 10, 1, 2, 3, 4, 5)), .Names = c(Cat, Ech
), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 10,
11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22,
23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 35,
36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 98, 99, 100, 101, 102, 103, 105, 106,
107, 108, 109, 110), class = data.frame)

I do not manage to avoid a do loop because very slow
I want to obtain a new dataframe df2 with a new variable CatEch.
CatEch is the paste of the 2 variables Cat and Ech
dput(df2)
structure(list(Cat = c(6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4,
4, 8, 8, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, 6, 7, 7,
7, 7, 7), Ech = c(8, 9, 10, 11, 12, 12, 13, 13, 11, 12, 13, 14,
14, 14, 9, 10, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 11, 11,
4, 5, 6, 7, 8, 8, 8, 9, 9, 8, 9, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5,
5, 1, 2, 3, 4, 5, 6, 6, 6, 7, 7, 7, 5, 6, 7, 8, 9, 9, 10, 10,
11, 11, 11, 11, 11, 11, 15, 5, 6, 7, 7, 8, 8, 8, 8, 9, 9, 13,
13, 14, 15, 15, 15, 10, 1, 2, 3, 4, 5), CatEch = c(6.08, 6.09,
6.10, 6.11, 6.12, 6.12, 6.13, 6.13, 4.11, 4.12,
4.13, 4.14, 4.14, 4.14, 8.09, 8.10, 9.05, 9.06,
9.07, 9.07, 9.07, 9.07, 9.07, 6.07, 6.08, 6.09,
6.10, 6.11, 6.11, 6.11, 7.04, 7.05, 7.06, 7.07,
7.08, 7.08, 7.08, 7.09, 7.09, 7.08, 7.09, 8.02,
8.03, 8.04, 8.05, 8.05, 8.05, 8.05, 8.05, 8.05,
8.05, 8.05, 8.01, 8.02, 8.03, 8.04, 8.05, 8.06,
8.06, 8.06, 8.07, 8.07, 8.07, 6.05, 6.06, 6.07,
6.08, 6.09, 6.09, 6.10, 6.10, 6.11, 6.11, 6.11,
6.11, 6.11, 6.11, 7.15, 8.05, 8.06, 8.07, 8.07,
8.08, 8.08, 8.08, 8.08, 8.09, 8.09, 2.13, 2.13,
2.14, 2.15, 2.15, 2.15, 6.10, 7.01, 7.02, 7.03,
7.04, 7.05)), .Names = c(Cat, Ech, CatEch), row.names = c(1,
2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14,
15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27,
28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39,
40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 98, 99,
100, 101, 102, 103, 105, 106, 107, 108, 109,
110), class = data.frame)
Any idea ?

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] to avoid a do loop

2013-09-08 Thread Arnaud Michel
Thanks to all three for your fast answer
Michel

Le 08/09/2013 18:41, Renaud Lancelot a écrit :
 paste(df1$Cat,
   formatC(df1$Ech, flag = 0, width = max(nchar(df1$Ech))),
   sep = .)



 2013/9/8 Arnaud Michel michel.arn...@cirad.fr 
 mailto:michel.arn...@cirad.fr

 Hello
 I have a large dataframe  (nrow=55000).
 This below df1 an extract of the original dataframe

 dput(df1)
 structure(list(Cat = c(6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4,
 4, 8, 8, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
 8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, 6, 7, 7,
 7, 7, 7), Ech = c(8, 9, 10, 11, 12, 12, 13, 13, 11, 12, 13, 14,
 14, 14, 9, 10, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 11, 11,
 4, 5, 6, 7, 8, 8, 8, 9, 9, 8, 9, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5,
 5, 1, 2, 3, 4, 5, 6, 6, 6, 7, 7, 7, 5, 6, 7, 8, 9, 9, 10, 10,
 11, 11, 11, 11, 11, 11, 15, 5, 6, 7, 7, 8, 8, 8, 8, 9, 9, 13,
 13, 14, 15, 15, 15, 10, 1, 2, 3, 4, 5)), .Names = c(Cat, Ech
 ), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 10,
 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22,
 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 35,
 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47,
 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 59,
 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71,
 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
 83, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94,
 95, 96, 98, 99, 100, 101, 102, 103, 105, 106,
 107, 108, 109, 110), class = data.frame)

 I do not manage to avoid a do loop because very slow
 I want to obtain a new dataframe df2 with a new variable CatEch.
 CatEch is the paste of the 2 variables Cat and Ech
 dput(df2)
 structure(list(Cat = c(6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4,
 4, 8, 8, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
 8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, 6, 7, 7,
 7, 7, 7), Ech = c(8, 9, 10, 11, 12, 12, 13, 13, 11, 12, 13, 14,
 14, 14, 9, 10, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 11, 11,
 4, 5, 6, 7, 8, 8, 8, 9, 9, 8, 9, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5,
 5, 1, 2, 3, 4, 5, 6, 6, 6, 7, 7, 7, 5, 6, 7, 8, 9, 9, 10, 10,
 11, 11, 11, 11, 11, 11, 15, 5, 6, 7, 7, 8, 8, 8, 8, 9, 9, 13,
 13, 14, 15, 15, 15, 10, 1, 2, 3, 4, 5), CatEch = c(6.08, 6.09,
 6.10, 6.11, 6.12, 6.12, 6.13, 6.13, 4.11, 4.12,
 4.13, 4.14, 4.14, 4.14, 8.09, 8.10, 9.05, 9.06,
 9.07, 9.07, 9.07, 9.07, 9.07, 6.07, 6.08, 6.09,
 6.10, 6.11, 6.11, 6.11, 7.04, 7.05, 7.06, 7.07,
 7.08, 7.08, 7.08, 7.09, 7.09, 7.08, 7.09, 8.02,
 8.03, 8.04, 8.05, 8.05, 8.05, 8.05, 8.05, 8.05,
 8.05, 8.05, 8.01, 8.02, 8.03, 8.04, 8.05, 8.06,
 8.06, 8.06, 8.07, 8.07, 8.07, 6.05, 6.06, 6.07,
 6.08, 6.09, 6.09, 6.10, 6.10, 6.11, 6.11, 6.11,
 6.11, 6.11, 6.11, 7.15, 8.05, 8.06, 8.07, 8.07,
 8.08, 8.08, 8.08, 8.08, 8.09, 8.09, 2.13, 2.13,
 2.14, 2.15, 2.15, 2.15, 6.10, 7.01, 7.02, 7.03,
 7.04, 7.05)), .Names = c(Cat, Ech, CatEch), row.names =
 c(1,
 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14,
 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27,
 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39,
 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51,
 52, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63,
 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75,
 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87,
 88, 89, 90, 91, 92, 93, 94, 95, 96, 98, 99,
 100, 101, 102, 103, 105, 106, 107, 108, 109,
 110), class = data.frame)
 Any idea ?

 -- 
 Michel ARNAUD
 Chargé de mission auprès du DRH
 DGDRD-Drh - TA 174/04
 Av Agropolis 34398 Montpellier cedex 5
 tel : 04.67.61.75.38
 fax : 04.67.61.57.87
 port: 06.47.43.55.31

 __
 R-help@r-project.org mailto: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.




 -- 
 Renaud Lancelot
 Directeur adjoint / Deputy director
 CIRAD, UMR15, Campus International de Baillarguet TA A-DIR / B
 F34398 Montpellier

 EDENext Project, coordinator: http://www.edenext.eu/

 Tel.  +33 4 67 59 37 17  -  Fax  +33 4 67 59 37 95
 Secr. +33 4 67 59 37 37  - Cell. +33 6 77 52 08 69

-- 
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read

Re: [R] to avoid a do loop

2013-09-08 Thread Arnaud Michel
Hi
This below system.time of the 3 solutions with a large dataframe df1 
(nrow=55000).

# Arun
system.time(df1$CatEch1 -
paste0(df1$Cat,.,sprintf(%02d,df1$Ech)))
#   user  system elapsed
#   0.060.000.06

# Rui Barradas
system.time(df1$CatEch2 -
pastedf1$Cat, sprintf(%02d, df1$Ech), sep = .) )
#   user  system elapsed
#   0.170.000.17

# R Lancelot
system.time(df1$CatEch3 -
paste(df1$Cat, formatC(df1$Ech, flag = 0,
width = max(nchar(df1$Ech))), sep = .))
#   user  system elapsed
#   0.340.000.35
Thanks
Michel

Le 08/09/2013 19:15, Arnaud Michel a écrit :
 Thanks to all three for your fast answer
 Michel

 Le 08/09/2013 18:41, Renaud Lancelot a écrit :
 paste(df1$Cat,
formatC(df1$Ech, flag = 0, width = max(nchar(df1$Ech))),
sep = .)



 2013/9/8 Arnaud Michel michel.arn...@cirad.fr
 mailto:michel.arn...@cirad.fr

  Hello
  I have a large dataframe  (nrow=55000).
  This below df1 an extract of the original dataframe

  dput(df1)
  structure(list(Cat = c(6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4,
  4, 8, 8, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
  7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, 6, 7, 7,
  7, 7, 7), Ech = c(8, 9, 10, 11, 12, 12, 13, 13, 11, 12, 13, 14,
  14, 14, 9, 10, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 11, 11,
  4, 5, 6, 7, 8, 8, 8, 9, 9, 8, 9, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5,
  5, 1, 2, 3, 4, 5, 6, 6, 6, 7, 7, 7, 5, 6, 7, 8, 9, 9, 10, 10,
  11, 11, 11, 11, 11, 11, 15, 5, 6, 7, 7, 8, 8, 8, 8, 9, 9, 13,
  13, 14, 15, 15, 15, 10, 1, 2, 3, 4, 5)), .Names = c(Cat, Ech
  ), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 10,
  11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22,
  23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 35,
  36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47,
  48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 59,
  60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71,
  72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
  83, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94,
  95, 96, 98, 99, 100, 101, 102, 103, 105, 106,
  107, 108, 109, 110), class = data.frame)

  I do not manage to avoid a do loop because very slow
  I want to obtain a new dataframe df2 with a new variable CatEch.
  CatEch is the paste of the 2 variables Cat and Ech
  dput(df2)
  structure(list(Cat = c(6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4,
  4, 8, 8, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
  7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, 6, 7, 7,
  7, 7, 7), Ech = c(8, 9, 10, 11, 12, 12, 13, 13, 11, 12, 13, 14,
  14, 14, 9, 10, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 11, 11,
  4, 5, 6, 7, 8, 8, 8, 9, 9, 8, 9, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5,
  5, 1, 2, 3, 4, 5, 6, 6, 6, 7, 7, 7, 5, 6, 7, 8, 9, 9, 10, 10,
  11, 11, 11, 11, 11, 11, 15, 5, 6, 7, 7, 8, 8, 8, 8, 9, 9, 13,
  13, 14, 15, 15, 15, 10, 1, 2, 3, 4, 5), CatEch = c(6.08, 6.09,
  6.10, 6.11, 6.12, 6.12, 6.13, 6.13, 4.11, 4.12,
  4.13, 4.14, 4.14, 4.14, 8.09, 8.10, 9.05, 9.06,
  9.07, 9.07, 9.07, 9.07, 9.07, 6.07, 6.08, 6.09,
  6.10, 6.11, 6.11, 6.11, 7.04, 7.05, 7.06, 7.07,
  7.08, 7.08, 7.08, 7.09, 7.09, 7.08, 7.09, 8.02,
  8.03, 8.04, 8.05, 8.05, 8.05, 8.05, 8.05, 8.05,
  8.05, 8.05, 8.01, 8.02, 8.03, 8.04, 8.05, 8.06,
  8.06, 8.06, 8.07, 8.07, 8.07, 6.05, 6.06, 6.07,
  6.08, 6.09, 6.09, 6.10, 6.10, 6.11, 6.11, 6.11,
  6.11, 6.11, 6.11, 7.15, 8.05, 8.06, 8.07, 8.07,
  8.08, 8.08, 8.08, 8.08, 8.09, 8.09, 2.13, 2.13,
  2.14, 2.15, 2.15, 2.15, 6.10, 7.01, 7.02, 7.03,
  7.04, 7.05)), .Names = c(Cat, Ech, CatEch), row.names =
  c(1,
  2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14,
  15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27,
  28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39,
  40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51,
  52, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63,
  64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75,
  76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87,
  88, 89, 90, 91, 92, 93, 94, 95, 96, 98, 99,
  100, 101, 102, 103, 105, 106, 107, 108, 109,
  110), class = data.frame)
  Any idea ?

  --
  Michel ARNAUD
  Chargé de mission auprès du DRH
  DGDRD-Drh - TA 174/04
  Av Agropolis 34398 Montpellier cedex 5
  tel : 04.67.61.75.38
  fax : 04.67.61.57.87
  port: 06.47.43.55.31

  __
  R-help@r-project.org mailto: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

Re: [R] To represent on the same plot the relation (y1, x) and (y2, x)

2013-09-01 Thread Arnaud Michel

Thank you Arun
Michel
Le 01/09/2013 07:36, arun a écrit :

Hi Arnaud,
No problem.
Try,
x- 1:10
  set.seed(28)
  y1- rnorm(10)
set.seed(485)
  y2- rnorm(10,25)
library(plotrix)
  
twoord.plot(x,y1,y2,lylim=c(-2,2),rylim=c(20,30),ylab=y1,rylab=y2,lcol=2,rcol=4,main=y1,
 y2 vs. x)

A.K.




- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: arun smartpink...@yahoo.com
Cc: R help r-help@r-project.org
Sent: Sunday, September 1, 2013 1:18 AM
Subject: Re: [R] To represent on the same plot the relation (y1, x) and (y2, x)

Thank you Arun
But have you a solution if y1 and y2 have not the same unit (ex : the
unit of y1 is meter and the unit of y2 is Kg)  and if I want the axe of
y1 at the left of the plot and the axe of y2 at the rigth of the plot
Michel

Le 31/08/2013 21:27, arun a écrit :

Hi,
May be this helps:
x- 1:10
set.seed(28)
y1- rnorm(10)
set.seed(485)
y2- rnorm(10)
plot(x,y1,col=red,type=b,ylab=y1:y2)
lines(y2,col=blue,type=b)
legend(topleft, legend = c(y1, y2),text.col=c(red,blue))



#or
library(ggplot2)
dat1- data.frame(x,y1,y2)
ggplot(dat1,aes(x))+geom_line(aes(y=y1,colour=y1))+
 geom_line(aes(y=y2,colour=y2)) +ylab(y1:y2)

A.K.





- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Saturday, August 31, 2013 1:57 PM
Subject: [R] To represent on the same plot the relation (y1, x) and (y2, x)

Hello,
I have 3 vectors x, y1 and y2
I would like to represent on the same plot the two graph (y1, x) and
(y2, x).
Is it possible with ggplot ? other package ?
Thanks for your help



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] To represent on the same plot the relation (y1, x) and (y2, x)

2013-09-01 Thread Arnaud Michel

Thank you Arun
But have you a solution if y1 and y2 have not the same unit (ex : the 
unit of y1 is meter and the unit of y2 is Kg)  and if I want the axe of 
y1 at the left of the plot and the axe of y2 at the rigth of the plot

Michel

Le 31/08/2013 21:27, arun a écrit :

Hi,
May be this helps:
  x- 1:10
  set.seed(28)
  y1- rnorm(10)
set.seed(485)
  y2- rnorm(10)
  plot(x,y1,col=red,type=b,ylab=y1:y2)
lines(y2,col=blue,type=b)
legend(topleft, legend = c(y1, y2),text.col=c(red,blue))



#or
library(ggplot2)
dat1- data.frame(x,y1,y2)
ggplot(dat1,aes(x))+geom_line(aes(y=y1,colour=y1))+
   geom_line(aes(y=y2,colour=y2)) +ylab(y1:y2)

A.K.





- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Saturday, August 31, 2013 1:57 PM
Subject: [R] To represent on the same plot the relation (y1, x) and (y2, x)

Hello,
I have 3 vectors x, y1 and y2
I would like to represent on the same plot the two graph (y1, x) and
(y2, x).
Is it possible with ggplot ? other package ?
Thanks for your help



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] To represent on the same plot the relation (y1, x) and (y2, x)

2013-08-31 Thread Arnaud Michel

Hello,
I have 3 vectors x, y1 and y2
I would like to represent on the same plot the two graph (y1, x) and 
(y2, x).

Is it possible with ggplot ? other package ?
Thanks for your help

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] Change values in a dateframe-Speed TEST

2013-07-25 Thread Arnaud Michel

Hi

For a dataframe with name PaysContrat1 and with
nrow(PaysContrat1)
[1] 52366

the test of system.time is :

system.time(droplevels(do.call(rbind,lapply(split(PaysContrat1,PaysContrat1$Matricule),
FUN=function(x) {x[,c(Nom,Prénom)] - 
x[nrow(x),c(Nom,Prénom),drop=TRUE];x}

   user  system elapsed
  14.030.00   14.04

system.time(droplevels(PaysContrat1[with(PaysContrat1,ave(seq_along(Matricule),Matricule,FUN=min)) 
,]  ))

   user  system elapsed
0.2 0.0 0.2

Michel

Le 24/07/2013 15:29, arun a écrit :

Hi Michel,
You could try:


df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),])
row.names(df1New)-1:nrow(df1New)
df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),])
row.names(df2New)-1:nrow(df2New)
  identical(df1New,df1)
#[1] TRUE
  identical(df2New,df2)
#[1] TRUE
A.K.



- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Wednesday, July 24, 2013 2:39 AM
Subject: [R] Change values in a dateframe

Hello

I have the following problem :
The dataframe TEST has multiple lines for a same person because :
there are differents values of Nom or differents values of Prenom
but the values of Matricule or Sexe or Date.de.naissance are the same.

TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L,
5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT
), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L,
2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine,
Jeannine, Michel, Michele, Michèle, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))


I would want to make homogeneous the information and would like built 2
dataframes :
df1 wich has the value of Nom and Prenom of the first lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged

df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L,
5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom =
structure(c(6L,
3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar,
Elodie, Jeanine, Michel, Michele, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))

df2 wich has the value of Nom and Prenom of the last lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged.

df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L,
4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE,
LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor),
  Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L,
  5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel,
  Michèle, Michelle, Victor), class = factor), Sexe =
structure(c(1L,
  1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin,
  Masculin), class = factor), Date.de.naissance = structure(c(4L,
  2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940,
  04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936,
  30/03/1935), class = factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))

Thank for your helps
Michel



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] Change values in a dateframe-Speed TEST

2013-07-25 Thread Arnaud Michel

But I just noticed that the two solutions are not comparable :
the change concern only Nom and Prenom (solution Berend) and not also 
Sexe or Date.de.naissance orother variables (solution Arun) that can 
changed. But my question was badly put.

Michel

Le 25/07/2013 08:06, Arnaud Michel a écrit :

Hi

For a dataframe with name PaysContrat1 and with
nrow(PaysContrat1)
[1] 52366

the test of system.time is :

system.time(droplevels(do.call(rbind,lapply(split(PaysContrat1,PaysContrat1$Matricule), 

FUN=function(x) {x[,c(Nom,Prénom)] - 
x[nrow(x),c(Nom,Prénom),drop=TRUE];x}

   user  system elapsed
  14.030.00   14.04

system.time(droplevels(PaysContrat1[with(PaysContrat1,ave(seq_along(Matricule),Matricule,FUN=min)) 
,]  ))

   user  system elapsed
0.2 0.0 0.2

Michel

Le 24/07/2013 15:29, arun a écrit :

Hi Michel,
You could try:


df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),]) 


row.names(df1New)-1:nrow(df1New)
df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),]) 


row.names(df2New)-1:nrow(df2New)
  identical(df1New,df1)
#[1] TRUE
  identical(df2New,df2)
#[1] TRUE
A.K.



- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Wednesday, July 24, 2013 2:39 AM
Subject: [R] Change values in a dateframe

Hello

I have the following problem :
The dataframe TEST has multiple lines for a same person because :
there are differents values of Nom or differents values of Prenom
but the values of Matricule or Sexe or Date.de.naissance are the same.

TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L,
5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT
), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L,
2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine,
Jeannine, Michel, Michele, Michèle, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 
07/12/1947,

  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))


I would want to make homogeneous the information and would like built 2
dataframes :
df1 wich has the value of Nom and Prenom of the first lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged

df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L,
5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom =
structure(c(6L,
3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar,
Elodie, Jeanine, Michel, Michele, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 
07/12/1947,

  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))

df2 wich has the value of Nom and Prenom of the last lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged.

df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L,
4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE,
LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor),
  Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L,
  5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel,
  Michèle, Michelle, Victor), class = factor), Sexe =
structure(c(1L,
  1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin,
  Masculin), class = factor), Date.de.naissance = 
structure(c(4L,

  2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940,
  04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 
29/12/1936,

  30/03/1935), class = factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))

Thank for your helps
Michel





--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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

Re: [R] Change values in a dateframe-Speed TEST

2013-07-25 Thread Arnaud Michel

Le 25/07/2013 08:50, Berend Hasselman a écrit :

On 25-07-2013, at 08:35, Arnaud Michel michel.arn...@cirad.fr wrote:


But I just noticed that the two solutions are not comparable :
the change concern only Nom and Prenom (solution Berend) and not also Sexe or 
Date.de.naissance orother variables (solution Arun) that can changed. But my 
question was badly put.

Indeed:-)

But that can be remedied with (small correction w.r.t. initial solution: 
drop=TRUE removed; not relevant here)

r1 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule),
 FUN=function(x) {x[,1:ncol(x)] - x[1,1:ncol(x)];x})))

and

r2 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule),
 FUN=function(x) {x[,1:ncol(x)] - 
x[nrow(x),1:ncol(x)];x})))

Thank you but I keep
{x[,c(Nom,Prénom)] - x[nrow(x),c(Nom,Prénom)];x} because in the 
dataframe there are other variables that I do not want to change. I want 
change only Nom and Prénom


PS : ?w.r.t.
Michel


Less elegant than alternative with ave

Berend


Michel

Le 25/07/2013 08:06, Arnaud Michel a écrit :

Hi

For a dataframe with name PaysContrat1 and with
nrow(PaysContrat1)
[1] 52366

the test of system.time is :

system.time(droplevels(do.call(rbind,lapply(split(PaysContrat1,PaysContrat1$Matricule),
FUN=function(x) {x[,c(Nom,Prénom)] - 
x[nrow(x),c(Nom,Prénom),drop=TRUE];x}
   user  system elapsed
  14.030.00   14.04

system.time(droplevels(PaysContrat1[with(PaysContrat1,ave(seq_along(Matricule),Matricule,FUN=min))
 ,]  ))
   user  system elapsed
0.2 0.0 0.2

Michel

Le 24/07/2013 15:29, arun a écrit :

Hi Michel,
You could try:


df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),])
row.names(df1New)-1:nrow(df1New)
df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),])
row.names(df2New)-1:nrow(df2New)
  identical(df1New,df1)
#[1] TRUE
  identical(df2New,df2)
#[1] TRUE
A.K.



- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Wednesday, July 24, 2013 2:39 AM
Subject: [R] Change values in a dateframe

Hello

I have the following problem :
The dataframe TEST has multiple lines for a same person because :
there are differents values of Nom or differents values of Prenom
but the values of Matricule or Sexe or Date.de.naissance are the same.

TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L,
5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT
), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L,
2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine,
Jeannine, Michel, Michele, Michèle, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))


I would want to make homogeneous the information and would like built 2
dataframes :
df1 wich has the value of Nom and Prenom of the first lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged

df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L,
5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom =
structure(c(6L,
3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar,
Elodie, Jeanine, Michel, Michele, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))

df2 wich has the value of Nom and Prenom of the last lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged.

df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L,
4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE,
LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor),
  Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L,
  5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel,
  Michèle, Michelle, Victor), class = factor), Sexe =
structure(c(1L,
  1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L

[R] Change values in a dateframe

2013-07-24 Thread Arnaud Michel

Hello

I have the following problem :
The dataframe TEST has multiple lines for a same person because :
there are differents values of Nom or differents values of Prenom
but the values of Matricule or Sexe or Date.de.naissance are the same.

TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L,
5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT
), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L,
2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine,
Jeannine, Michel, Michele, Michèle, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = 
factor),

Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = 
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, 
row.names = c(NA,

-11L))


I would want to make homogeneous the information and would like built 2 
dataframes :
df1 wich has the value of Nom and Prenom of the first lines of TEST when 
there are different values. The other values (Matricule or Sexe or 
Date.de.naissance) are unchanged


df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L,
5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom = 
structure(c(6L,

3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar,
Elodie, Jeanine, Michel, Michele, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = 
factor),

Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = 
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, 
row.names = c(NA,

-11L))

df2 wich has the value of Nom and Prenom of the last lines of TEST when 
there are different values. The other values (Matricule or Sexe or 
Date.de.naissance) are unchanged.


df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L,
4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE,
LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor),
Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L,
5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel,
Michèle, Michelle, Victor), class = factor), Sexe = 
structure(c(1L,

1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin,
Masculin), class = factor), Date.de.naissance = structure(c(4L,
2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940,
04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936,
30/03/1935), class = factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, 
row.names = c(NA,

-11L))

Thank for your helps
Michel

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] Change values in a dateframe

2013-07-24 Thread Arnaud Michel

Thank you Berend
It is exactly what I wanted.
Michel
Le 24/07/2013 09:48, Berend Hasselman a écrit :

On 24-07-2013, at 08:39, Arnaud Michel michel.arn...@cirad.fr wrote:


Hello

I have the following problem :
The dataframe TEST has multiple lines for a same person because :
there are differents values of Nom or differents values of Prenom
but the values of Matricule or Sexe or Date.de.naissance are the same.

TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L,
5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT
), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L,
2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine,
Jeannine, Michel, Michele, Michèle, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor),
Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = 
c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names 
= c(NA,
-11L))


I would want to make homogeneous the information and would like built 2 
dataframes :
df1 wich has the value of Nom and Prenom of the first lines of TEST when there 
are different values. The other values (Matricule or Sexe or Date.de.naissance) 
are unchanged

df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L,
5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom = 
structure(c(6L,
3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar,
Elodie, Jeanine, Michel, Michele, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class = factor),
Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class = factor)), .Names = 
c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names 
= c(NA,
-11L))

df2 wich has the value of Nom and Prenom of the last lines of TEST when there 
are different values. The other values (Matricule or Sexe or Date.de.naissance) 
are unchanged.

df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L,
4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE,
LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor),
Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L,
5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel,
Michèle, Michelle, Victor), class = factor), Sexe = structure(c(1L,
1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin,
Masculin), class = factor), Date.de.naissance = structure(c(4L,
2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940,
04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936,
30/03/1935), class = factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame, row.names 
= c(NA,
-11L))


Something like this

r1 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule),
 FUN=function(x) {x[,c(Nom,Prenom)] - 
x[1,c(Nom,Prenom),drop=TRUE];x})))
rownames(r1) - NULL
r1

r2 - droplevels(do.call(rbind,lapply(split(TEST,TEST$Matricule),
 FUN=function(x) {x[,c(Nom,Prenom)] - 
x[nrow(x),c(Nom,Prenom),drop=TRUE];x})))
rownames(r2) - NULL
r2

# identical(r1,df1)
#[1] TRUE
# identical(r2,df2)
#[1] TRUE

Note: I had to change the Prenom and Sexe columns because of encoding issues. 
but that shouldn't have any influence on the above.

Berend





--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] Change values in a dateframe

2013-07-24 Thread Arnaud Michel

Hi Arun,
Merci à toi
Bien amicalement
Michel
Le 24/07/2013 15:29, arun a écrit :

Hi Michel,
You could try:


df1New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),])
row.names(df1New)-1:nrow(df1New)
df2New-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),])
row.names(df2New)-1:nrow(df2New)
  identical(df1New,df1)
#[1] TRUE
  identical(df2New,df2)
#[1] TRUE
A.K.



- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: R help r-help@r-project.org
Cc:
Sent: Wednesday, July 24, 2013 2:39 AM
Subject: [R] Change values in a dateframe

Hello

I have the following problem :
The dataframe TEST has multiple lines for a same person because :
there are differents values of Nom or differents values of Prenom
but the values of Matricule or Sexe or Date.de.naissance are the same.

TEST - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 8L,
5L, 6L, 9L, 3L, 3L, 7L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, LANGUE-LOPEZ, RIVIER, TRU, VINCENT
), class = factor), Prenom = structure(c(8L, 3L, 4L, 5L, 1L,
2L, 2L, 9L, 6L, 7L, 7L), .Label = c(Edgar, Elodie, Jeanine,
Jeannine, Michel, Michele, Michèle, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))


I would want to make homogeneous the information and would like built 2
dataframes :
df1 wich has the value of Nom and Prenom of the first lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged

df1 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 4L, 6L,
5L, 5L, 7L, 3L, 3L, 3L), .Label = c(CHICHE, GEOF, GUTIER,
JACQUE, LANGUE, TRU, VINCENT), class = factor), Prenom =
structure(c(6L,
3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L, 5L, 5L), .Label = c(Edgar,
Elodie, Jeanine, Michel, Michele, Michelle, Victor
), class = factor), Sexe = structure(c(1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin, Masculin), class =
factor),
  Date.de.naissance = structure(c(4L, 2L, 2L, 7L, 6L, 5L, 5L,
  1L, 3L, 3L, 3L), .Label = c(03/09/1940, 04/03/1946, 07/12/1947,
  18/11/1945, 27/09/1947, 29/12/1936, 30/03/1935), class =
factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))

df2 wich has the value of Nom and Prenom of the last lines of TEST when
there are different values. The other values (Matricule or Sexe or
Date.de.naissance) are unchanged.

df2 - structure(list(Matricule = c(66L, 67L, 67L, 68L, 89L, 90L, 90L,
91L, 108L, 108L, 108L), Nom = structure(c(1L, 2L, 2L, 3L, 6L,
4L, 4L, 7L, 5L, 5L, 5L), .Label = c(CHICHE, GEOF, JACQUE,
LANGUE-LOPEZ, RIVIER, TRU, VINCENT), class = factor),
  Prenom = structure(c(6L, 3L, 3L, 4L, 1L, 2L, 2L, 7L, 5L,
  5L, 5L), .Label = c(Edgar, Elodie, Jeannine, Michel,
  Michèle, Michelle, Victor), class = factor), Sexe =
structure(c(1L,
  1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c(Féminin,
  Masculin), class = factor), Date.de.naissance = structure(c(4L,
  2L, 2L, 7L, 6L, 5L, 5L, 1L, 3L, 3L, 3L), .Label = c(03/09/1940,
  04/03/1946, 07/12/1947, 18/11/1945, 27/09/1947, 29/12/1936,
  30/03/1935), class = factor)), .Names = c(Matricule,
Nom, Prenom, Sexe, Date.de.naissance), class = data.frame,
row.names = c(NA,
-11L))

Thank for your helps
Michel



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] Calculate interaction for a big dataframe

2013-07-22 Thread Arnaud Michel

Hi

To calculate the value of the interaction between factors of a dataframe 
df, does exist any function which could replace the function when the 
dataframe df has the numbers of rows of df is large (~55000) and also 
the numbers of combinaison of the three factors is large. The calcul abort.

The function to calculate the interaction is :
as.numeric(interaction(df [,c(1:3)],drop=TRUE))

To complete the question and to calculate interaction beetween 3 factors 
f1, f2, f3, does it possible to calculate first f12 = interaction 
(f1,f2) and after calculate interaction (f12, f3).

It seems to me that yes.

Thanks for your help




--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] Calculate interaction for a big dataframe

2013-07-22 Thread Arnaud Michel

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 :

Hi

you maybe could use paste


f1-sample(letters[1:3], 10, replace=T)
f2-sample(letters[4:7], 10, replace=T)
f3-sample(letters[9:11], 10, replace=T)
interaction(f1, f2, f3, drop=T)

  [1] c.e.j b.e.j a.e.j c.g.i a.f.j b.g.k a.e.i a.e.k a.d.j b.e.j
Levels: a.e.i c.g.i a.d.j a.e.j b.e.j c.e.j a.f.j a.e.k b.g.k

paste(f1, f2, f3, sep=.)

  [1] c.e.j b.e.j a.e.j c.g.i a.f.j b.g.k a.e.i a.e.k a.d.j
[10] b.e.j

The difference is that interaction gives you directly factor, paste gives you 
character vector, but it may be convenient too for your purpose.

Regards
Petr



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of Arnaud Michel
Sent: Monday, July 22, 2013 10:57 AM
To: R help
Subject: [R] Calculate interaction for a big dataframe

Hi

To calculate the value of the interaction between factors of a
dataframe df, does exist any function which could replace the function
when the dataframe df has the numbers of rows of df is large (~55000)
and also the numbers of combinaison of the three factors is large. The
calcul abort.
The function to calculate the interaction is :
as.numeric(interaction(df [,c(1:3)],drop=TRUE))

To complete the question and to calculate interaction beetween 3
factors f1, f2, f3, does it possible to calculate first f12 =
interaction
(f1,f2) and after calculate interaction (f12, f3).
It seems to me that yes.

Thanks for your help




--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] Question on plotting with googleVis

2013-07-17 Thread Arnaud Michel

Hi
You can do a rotation and use gvisColumnChart instead gvisBarChart
plot(gvisColumnChart(MyData, xvar=Names1, yvar=c(Values1,
Values2),options=list(width=2500,height=1000)))
Michel



Le 17/07/2013 15:57, Christofer Bogaso a écrit :

Hello Arnaud,

Thank you for your pointer. However I need to more clarification.

I want to control the max. and min. values for the x-axis, as well as
number of vertical gridlines to be displayed. I tried the following:


MyData - data.frame(Names1 = paste(XXX, 1:150), Values1 = 1:150 +
10, Values2 = 1:150)
library(googleVis)
plot(gvisBarChart(MyData, xvar=Names1, yvar=c(Values1,
Values2),options=list(width=1200,height=1500,hAxis.gridlines =
{count: 10},hAxis.minValue = 0, hAxis.maxValue = 100)))

However this is not clearly working. Can someone point me what went wrong?

Thanks and regards,




On 7/16/13, Arnaud Michel michel.arn...@cirad.fr wrote:

You can try with list options :

plot(gvisBarChart(MyData, xvar=Names1, yvar=c(Values1, Values2),
options=list(width=1200,height=1500)))



Le 15/07/2013 20:00, Christofer Bogaso a écrit :

Hello again,

Let say I have following data-frame:

MyData - data.frame(Names1 = paste(XXX, 1:150), Values1 = 1:150 + 10,
Values2 = 1:150)

Now I want to plot this data-frame with googleVis. Therefore I run
following codes:

library(googleVis)
plot(gvisBarChart(MyData, xvar=Names1, yvar=c(Values1, Values2)))

However the problem is that, hardly this plot can be read. However if I
plot a fraction of my data-frame then the underlying plot is clearly
visible:

plot(gvisBarChart(MyData[1:15,], xvar=Names1, yvar=c(Values1,
Values2)))  ## This is clearly visible.


I would really appreciate if someone gives me some pointer how I can
clearly plot my data-frame with googleVis. I understand that there are
many
other plotting methods available with R like ggplot, however here I want
to
use googleVis because of its strength in showing the values within the
plot
area itself if you hover your mouse.

Thanks and regards,

[[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.


--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31




--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] simplify a dataframe

2013-07-17 Thread Arnaud Michel
Hi Arun

I have two questions always about the question of symplify a dataframe

I would like
1)  to transform the vector x1 into the vector y1
x1 - c(1,1,1,-1000, 1,-1000,  1,1,1,1,1,1,-1000)
y1 - c(1,1,1,1,2,2, 3,3,3,3,3,3,3)


2) to transform the vectors Debut and Fin by taking into account INDX 
into the two vectors Deb and Fin
Debut - c (
24/01/1995, 01/05/1997 ,31/12/1997, 02/02/1995 ,28/02/1995 
,01/03/1995,
13/03/1995, 01/01/1996, 31/01/1996, 24/01/1995, 01/07/1995 
,01/09/1995,
  01/07/1997, 01/01/1998, 01/08/1998, 01/01/2000, 
17/01/2000,29/02/2000)

Fin - c (
30/04/1997, 30/12/1997 ,31/12/1997, 27/02/1995, 28/02/1995, 
12/03/1995,
30/06/1995, 30/01/1996, 31/01/1996, 30/06/1995, 31/08/1995, 
30/06/1997,
31/12/1997, 31/07/1998, 31/12/1999, 16/01/2000, 28/02/2000, 
29/02/2000)

INDX - c(6,6,6,11,11,11, 4,5,5)


Deb  - c(*24/01/1995*, *02/02/1995*, *13/03/1995*,   
*01/01/1996*)
Fi n  -  c(*31/12/1997*, *12/03/1995*, *30/06/1995*,  
*31/01/1996*)


  DebutFin INDX
*24/01/1995* 30/04/19976
01/05/1997 30/12/19976
31/12/1997 *31/12/1997*6
*02/02/1995* 27/02/1995   11
28/02/1995 28/02/1995   11
01/03/1995 *12/03/1995*   11
*13/03/1995* *30/06/1995*4
*01/01/1996* 30/01/19965
31/01/1996 *31/01/1996*5


Thanks for your help

-- 
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31


[[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.


Re: [R] simplify a dataframe

2013-07-17 Thread Arnaud Michel

 Thank you for the question (1)
Sorry for the imprecision for the question (2) :
Suppose the date frame df
df1 - data.frame(
Debut =c ( 24/01/1995, 01/05/1997 ,31/12/1997, 02/02/1995 
,28/02/1995

,01/03/1995, 13/03/1995, 01/01/1996, 31/01/1996) ,
Fin = c ( 30/04/1997, 30/12/1997 ,31/12/1997, 27/02/1995, 
28/02/1995,

12/03/1995, 30/06/1995, 30/01/1996, 31/01/1996) ,
INDX = c(6,6,6,  11,11,11, 4,  5,5) )


I would like replace df1  by df2

df2 - data.frame(
Deb  = c(24/01/1995, 02/02/1995, 13/03/1995,
01/01/1996) ,
Fin  = c(31/12/1997, 12/03/1995, 30/06/1995,
31/01/1996) )

Explication :
The lines 1, 2 3 of df1 (who have same value of index =6) are replaced 
by only one line with

value of Debut of df2 = Debut of line 1 of df1
value of Fin of df2 = Fin of line 3 of df1

The lines 4,5,6 of df1 (who have same value of index =11) are replaced 
by only one line with

value of Debut of df2 = Debut of line 4 of df1
and value of fin of df2 = Fin of line 6 of df1

The line 7 of df1 (who have same value of index =4) are replaced by only 
one line with

value of Debut of df2 = Debut of line 7of df1
and value of fin of df2 = Fin of line 7of df1
== No change

The lines 8,9 of df1 (who have same value of index =5) are replaced by 
only one line with

value of Debut of df2 = Debut of line 8of df1
and value of fin of df2 = Fin of line 9 of df1

df1
   DebutFin INDX
1 24/01/1995 30/04/19976
2 01/05/1997 30/12/19976
3 31/12/1997 31/12/19976
4 02/02/1995 27/02/1995   11
5 28/02/1995 28/02/1995   11
6 01/03/1995 12/03/1995   11
7 13/03/1995 30/06/19954
8 01/01/1996 30/01/19965
9 31/01/1996 31/01/19965

 DebFin
1 24/01/1995 31/12/1997
2 02/02/1995 12/03/1995
3 13/03/1995 30/06/1995
4 01/01/1996 31/01/1996
Thank you for your helps
Michel

Le 17/07/2013 19:57, Rui Barradas a écrit :

Hello,

As for question (1), try the following.


y2 - cumsum(c(TRUE, diff(x1)  0))
identical(as.integer(y1), y2)  # y1 is of class numeric


As for question (2) I'm not understanding it.

Hope this helps,

Rui Barradas

Em 17-07-2013 18:21, Arnaud Michel escreveu:

Hi Arun

I have two questions always about the question of symplify a dataframe

I would like
1)  to transform the vector x1 into the vector y1
x1 - c(1,1,1,-1000, 1,-1000, 1,1,1,1,1,1,-1000)
y1 - c(1,1,1,1,2,2, 3,3,3,3,3,3,3)


2) to transform the vectors Debut and Fin by taking into account INDX
into the two vectors Deb and Fin
Debut - c (
24/01/1995, 01/05/1997 ,31/12/1997, 02/02/1995 ,28/02/1995
,01/03/1995,
13/03/1995, 01/01/1996, 31/01/1996, 24/01/1995, 01/07/1995
,01/09/1995,
   01/07/1997, 01/01/1998, 01/08/1998, 01/01/2000,
17/01/2000,29/02/2000)

Fin - c (
30/04/1997, 30/12/1997 ,31/12/1997, 27/02/1995, 28/02/1995,
12/03/1995,
30/06/1995, 30/01/1996, 31/01/1996, 30/06/1995, 31/08/1995,
30/06/1997,
31/12/1997, 31/07/1998, 31/12/1999, 16/01/2000, 28/02/2000,
29/02/2000)

INDX - c(6,6,6,11,11,11, 4,5,5)


Deb  - c(*24/01/1995*, *02/02/1995*, *13/03/1995*,
*01/01/1996*)
Fi n  -  c(*31/12/1997*, *12/03/1995*, *30/06/1995*,
*31/01/1996*)


   DebutFin INDX
*24/01/1995* 30/04/19976
01/05/1997 30/12/19976
31/12/1997 *31/12/1997*6
*02/02/1995* 27/02/1995   11
28/02/1995 28/02/1995   11
01/03/1995 *12/03/1995*   11
*13/03/1995* *30/06/1995*4
*01/01/1996* 30/01/19965
31/01/1996 *31/01/1996*5


Thanks for your help



__
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.





--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] simplify a dataframe

2013-07-17 Thread Arnaud Michel

Thanks Arun and Rui for your helps
Michel
Le 17/07/2013 22:20, arun a écrit :

#or
library(plyr)
res-ddply(df1,.(INDX),summarize,Debut=head(Debut,1),Fin=tail(Fin,1))
res$INDX-factor(res$INDX,levels=unique(df1$INDX))
res[order(res$INDX),-1]
#   DebutFin
#3 24/01/1995 31/12/1997
#4 02/02/1995 12/03/1995
#1 13/03/1995 30/06/1995
#2 01/01/1996 31/01/1996
A.K.



- Original Message -
From: arun smartpink...@yahoo.com
To: Arnaud Michel michel.arn...@cirad.fr
Cc: R help r-help@r-project.org; Rui Barradas ruipbarra...@sapo.pt
Sent: Wednesday, July 17, 2013 4:14 PM
Subject: Re: [R] simplify a dataframe

Hi,
You could try:

df1[,1:2]-lapply(df1[,1:2],as.character)
  df2New- data.frame(Deb=unique(with(df1,ave(Debut,INDX,FUN=function(x) 
head(x,1,Fin=unique(with(df1,ave(Fin,INDX,FUN=function(x) tail(x,1)
identical(df2New,df2)
#[1] TRUE

A.K.


- Original Message -
From: Arnaud Michel michel.arn...@cirad.fr
To: Rui Barradas ruipbarra...@sapo.pt; R help r-help@r-project.org; arun 
smartpink...@yahoo.com
Cc:
Sent: Wednesday, July 17, 2013 4:03 PM
Subject: Re: [R] simplify a dataframe

   Thank you for the question (1)
Sorry for the imprecision for the question (2) :
Suppose the date frame df
df1 - data.frame(
Debut =c ( 24/01/1995, 01/05/1997 ,31/12/1997, 02/02/1995
,28/02/1995
,01/03/1995, 13/03/1995, 01/01/1996, 31/01/1996) ,
Fin = c ( 30/04/1997, 30/12/1997 ,31/12/1997, 27/02/1995,
28/02/1995,
12/03/1995, 30/06/1995, 30/01/1996, 31/01/1996) ,
INDX = c(6,6,6,  11,11,11, 4,  5,5) )


I would like replace df1  by df2

df2 - data.frame(
Deb  = c(24/01/1995, 02/02/1995, 13/03/1995,
01/01/1996) ,
Fin  = c(31/12/1997, 12/03/1995, 30/06/1995,
31/01/1996) )

Explication :
The lines 1, 2 3 of df1 (who have same value of index =6) are replaced
by only one line with
value of Debut of df2 = Debut of line 1 of df1
value of Fin of df2 = Fin of line 3 of df1

The lines 4,5,6 of df1 (who have same value of index =11) are replaced
by only one line with
value of Debut of df2 = Debut of line 4 of df1
and value of fin of df2 = Fin of line 6 of df1

The line 7 of df1 (who have same value of index =4) are replaced by only
one line with
value of Debut of df2 = Debut of line 7of df1
and value of fin of df2 = Fin of line 7of df1
== No change

The lines 8,9 of df1 (who have same value of index =5) are replaced by
only one line with
value of Debut of df2 = Debut of line 8of df1
and value of fin of df2 = Fin of line 9 of df1

df1
 DebutFin INDX
1 24/01/1995 30/04/19976
2 01/05/1997 30/12/19976
3 31/12/1997 31/12/19976
4 02/02/1995 27/02/1995   11
5 28/02/1995 28/02/1995   11
6 01/03/1995 12/03/1995   11
7 13/03/1995 30/06/19954
8 01/01/1996 30/01/19965
9 31/01/1996 31/01/19965

   DebFin
1 24/01/1995 31/12/1997
2 02/02/1995 12/03/1995
3 13/03/1995 30/06/1995
4 01/01/1996 31/01/1996
Thank you for your helps
Michel

Le 17/07/2013 19:57, Rui Barradas a écrit :

Hello,

As for question (1), try the following.


y2 - cumsum(c(TRUE, diff(x1)  0))
identical(as.integer(y1), y2)  # y1 is of class numeric


As for question (2) I'm not understanding it.

Hope this helps,

Rui Barradas

Em 17-07-2013 18:21, Arnaud Michel escreveu:

Hi Arun

I have two questions always about the question of symplify a dataframe

I would like
1)  to transform the vector x1 into the vector y1
x1 - c(1,1,1,-1000, 1,-1000, 1,1,1,1,1,1,-1000)
y1 - c(1,1,1,1,2,2, 3,3,3,3,3,3,3)


2) to transform the vectors Debut and Fin by taking into account INDX
into the two vectors Deb and Fin
Debut - c (
24/01/1995, 01/05/1997 ,31/12/1997, 02/02/1995 ,28/02/1995
,01/03/1995,
13/03/1995, 01/01/1996, 31/01/1996, 24/01/1995, 01/07/1995
,01/09/1995,
 01/07/1997, 01/01/1998, 01/08/1998, 01/01/2000,
17/01/2000,29/02/2000)

Fin - c (
30/04/1997, 30/12/1997 ,31/12/1997, 27/02/1995, 28/02/1995,
12/03/1995,
30/06/1995, 30/01/1996, 31/01/1996, 30/06/1995, 31/08/1995,
30/06/1997,
31/12/1997, 31/07/1998, 31/12/1999, 16/01/2000, 28/02/2000,
29/02/2000)

INDX - c(6,6,6,11,11,11, 4,5,5)


Deb  - c(*24/01/1995*, *02/02/1995*, *13/03/1995*,
*01/01/1996*)
Fi n  -  c(*31/12/1997*, *12/03/1995*, *30/06/1995*,
*31/01/1996*)


 DebutFin INDX
*24/01/1995* 30/04/19976
01/05/1997 30/12/19976
31/12/1997 *31/12/1997*6
*02/02/1995* 27/02/1995   11
28/02/1995 28/02/1995   11
01/03/1995 *12/03/1995*   11
*13/03/1995* *30/06/1995*4
*01/01/1996* 30/01/19965
31/01/1996 *31/01/1996*5


Thanks for your help



__
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.



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38

Re: [R] Question on plotting with googleVis

2013-07-16 Thread Arnaud Michel

You can try with list options :

plot(gvisBarChart(MyData, xvar=Names1, yvar=c(Values1, Values2),
options=list(width=1200,height=1500)))



Le 15/07/2013 20:00, Christofer Bogaso a écrit :

Hello again,

Let say I have following data-frame:

MyData - data.frame(Names1 = paste(XXX, 1:150), Values1 = 1:150 + 10,
Values2 = 1:150)

Now I want to plot this data-frame with googleVis. Therefore I run
following codes:

library(googleVis)
plot(gvisBarChart(MyData, xvar=Names1, yvar=c(Values1, Values2)))

However the problem is that, hardly this plot can be read. However if I
plot a fraction of my data-frame then the underlying plot is clearly
visible:

plot(gvisBarChart(MyData[1:15,], xvar=Names1, yvar=c(Values1,
Values2)))  ## This is clearly visible.


I would really appreciate if someone gives me some pointer how I can
clearly plot my data-frame with googleVis. I understand that there are many
other plotting methods available with R like ggplot, however here I want to
use googleVis because of its strength in showing the values within the plot
area itself if you hover your mouse.

Thanks and regards,

[[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.



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


Re: [R] simplify a dataframe

2013-07-14 Thread Arnaud Michel
Hi,
Excuse me for the indistinctness
Le 13/07/2013 17:18, arun a écrit :
 Hi,
 when the value of Debut of lines i = value Fin of lines i-1
 That part is not clear esp. when it is looked upon with the expected output 
 (df2).
I want to group the lines which have the same caracteristics (Matricule, 
Nom, Sexe, DateNaissance, Contrat, Pays) and with period of time 
(Debut/start and Fin/end) without interruption of time.
For exemple :
The following three lines : Debut/Start  Fin/End
1  VERON  Féminin02/09/1935 CDI commun  France 
*24/01/1995* 30/04/1997
1  VERON  Féminin02/09/1935 CDI commun  France 
01/05/1997 30/12/1997
1  VERON  Féminin02/09/1935 CDI commun  France 
31/12/1997 *31/12/1997*
are transformed into 1 line
1  VERON  Féminin02/09/1935 CDI commun  France 
*24/01/1995* *31/12/1997*
because same caracteristicsand period of time without interruption of 
time (from *24/01/1995* to *31/12/1997)*

The following six lines :
6 BENARD Masculin01/04/1935 CDI commun Philippines 
*02/02/1995* 27/02/1995
6 BENARD Masculin01/04/1935 CDI commun Philippines 
28/02/1995 28/02/1995
6 BENARD Masculin01/04/1935 CDI commun Philippines 
01/03/1995 *12/03/1995*
6 BENARD Masculin01/04/1935 CDI commun  France 
*13/03/1995* *30/06/1995*
6 BENARD Masculin01/04/1935 CDI commun  France 
*01/01/1996* 30/01/1996
6 BENARD Masculin01/04/1935 CDI commun  France 
31/01/1996 *31/01/1996*
are transformed into
6 BENARD Masculin01/04/1935 CDI commun Philippines 
*02/02/1995* *12/03/1995*
6 BENARD Masculin01/04/1935 CDI commun  France 
*13/03/1995* *30/06/1995*
6 BENARD Masculin01/04/1935 CDI commun  France 
*01/01/1996* *31/01/1996*
because
lines 1-3 identical for caracteristics and without interruption in time
lines 4 and lines 5-6 are not grouped because there is an interruption 
in time beetween *30/06/1995 *and *01/01/1996*

Thank you for your help
Michel

Also, in your example dataset:

 df1$contrat[grep(^CDD,df1$contrat)]
 #[1] CDD détaché ext. Cirad CDD détaché ext. Cirad CDD détaché ext. 
 Cirad
 #[4] CDD détaché ext. Cirad CDD détaché ext.Cirad  CDD détaché ext. 
 Cirad
 #[7] CDD détaché ext. Cirad CDD détaché ext.Cirad  CDD détaché ext. 
 Cirad
 ##Looks like there are extra spaces in some of them.  I guess these are the 
 same
 df1$contrat[grep(^CDD,df1$contrat)]- CDD détaché ext. Cirad


 I tried this:
 indx-as.numeric(interaction(df1[,1:6],drop=FALSE))

   df1New- df1
 res2-unique(within(df1New,{Debut-ave(seq_along(indx),indx,FUN=function(x) 
 Debut[head(x,1)]);Fin- ave(seq_along(indx),indx,FUN=function(x) 
 Fin[tail(x,1)])}))
   row.names(res2)- 1:nrow(res2)

 res2[,c(1,2,7:8)]
 MatriculeNom  DebutFin
 1  1  VERON 24/01/1995 31/12/1997
 2  6 BENARD 02/02/1995 12/03/1995
 3  6 BENARD 13/03/1995 31/01/1996 ###here not correct
 4  8 DALNIC 24/01/1995 31/08/1995
 5  8 DALNIC 01/09/1995 29/02/2000
 6934  FORNI 26/01/1995 31/08/2001
 7934  FORNI 01/09/2001 31/08/2004
 8934  FORNI 01/09/2004 31/08/2007
 9934  FORNI 01/09/2007 04/09/2012
 10   934  FORNI 05/09/2012 31/12/4712


 df2[,c(1,2,7:8)]
 MatNom  DebutFin
 11  VERON 24/01/1995 31/12/1997
 26 BENARD 02/02/1995 12/03/1995
 36 BENARD 13/03/1995 30/06/1995
 46 BENARD 01/01/1996 31/01/1996 #missing this row
 58 DALNIC 24/01/1995 31/08/1995
 68 DALNIC 01/09/1995 29/02/2000
 7  934  FORNI 26/01/1995 31/08/2001
 8  934  FORNI 01/09/2001 31/08/2004
 9  934  FORNI 01/09/2004 31/08/2007
 10 934  FORNI 01/09/2007 04/09/2012
 11 934  FORNI 05/09/2012 31/12/4712


 Here, the dates look similar to the ones on df2 except for one row in df2.

 A.K.




 - Original Message -
 From: Arnaud Michel michel.arn...@cirad.fr
 To: R help r-help@r-project.org
 Cc:
 Sent: Friday, July 12, 2013 3:45 PM
 Subject: [R] simplify a dataframe

 Hello

 I have the following problem : group the lines of a dataframe when no
 information change (Matricule, Nom, Sexe, DateNaissance, Contrat, Pays)
 and when the value of Debut of lines i = value Fin of lines i-1
 I can obtain it with a do loop. Is it possible to avoid the loop ?

 The dataframe initial is df1
 dput(df1)
 structure(list(Matricule = c(1L, 1L, 1L, 6L, 6L, 6L, 6L, 6L,
 6L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 934L, 934L, 934L, 934L,
 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
 934L, 934L, 934L, 934L), Nom = c(VERON, VERON, VERON, BENARD,
 BENARD, BENARD, BENARD, BENARD, BENARD, DALNIC, DALNIC,
 DALNIC, DALNIC, DALNIC, DALNIC, DALNIC, DALNIC, DALNIC,
 FORNI, FORNI, FORNI, FORNI, FORNI, FORNI, FORNI,
 FORNI, FORNI, FORNI, FORNI, FORNI, FORNI, FORNI,
 FORNI, FORNI, FORNI, FORNI

Re: [R] simplify a dataframe

2013-07-14 Thread Arnaud Michel
An other remark :
If I calculate
df1$D- as.numeric(as.Date(paste0(substr(df1$Debut,7,10),-,
substr(df1$Debut,4,5),-,substr(df1$Debut,1,2
and
df1$F - as.numeric(as.Date(paste0(substr(df1$Fin,7,10),-,
substr(df1$Fin,4,5),-,substr(df1$Fin,1,2
and if there is no interruption of time for the lines i and i+1
then df1$F[i] + 1 == df1$D[i+1]
Michel

Le 14/07/2013 18:17, Arnaud Michel a écrit :
 Hi,
 Excuse me for the indistinctness
 Le 13/07/2013 17:18, arun a écrit :
 Hi,
 when the value of Debut of lines i = value Fin of lines i-1
 That part is not clear esp. when it is looked upon with the expected output 
 (df2).
 I want to group the lines which have the same caracteristics (Matricule,
 Nom, Sexe, DateNaissance, Contrat, Pays) and with period of time
 (Debut/start and Fin/end) without interruption of time.
 For exemple :
 The following three lines : Debut/Start  Fin/End
 1  VERON  Féminin02/09/1935 CDI commun  France
 *24/01/1995* 30/04/1997
 1  VERON  Féminin02/09/1935 CDI commun  France
 01/05/1997 30/12/1997
 1  VERON  Féminin02/09/1935 CDI commun  France
 31/12/1997 *31/12/1997*
 are transformed into 1 line
 1  VERON  Féminin02/09/1935 CDI commun  France
 *24/01/1995* *31/12/1997*
 because same caracteristicsand period of time without interruption of
 time (from *24/01/1995* to *31/12/1997)*

 The following six lines :
 6 BENARD Masculin01/04/1935 CDI commun Philippines
 *02/02/1995* 27/02/1995
 6 BENARD Masculin01/04/1935 CDI commun Philippines
 28/02/1995 28/02/1995
 6 BENARD Masculin01/04/1935 CDI commun Philippines
 01/03/1995 *12/03/1995*
 6 BENARD Masculin01/04/1935 CDI commun  France
 *13/03/1995* *30/06/1995*
 6 BENARD Masculin01/04/1935 CDI commun  France
 *01/01/1996* 30/01/1996
 6 BENARD Masculin01/04/1935 CDI commun  France
 31/01/1996 *31/01/1996*
 are transformed into
 6 BENARD Masculin01/04/1935 CDI commun Philippines
 *02/02/1995* *12/03/1995*
 6 BENARD Masculin01/04/1935 CDI commun  France
 *13/03/1995* *30/06/1995*
 6 BENARD Masculin01/04/1935 CDI commun  France
 *01/01/1996* *31/01/1996*
 because
 lines 1-3 identical for caracteristics and without interruption in time
 lines 4 and lines 5-6 are not grouped because there is an interruption
 in time beetween *30/06/1995 *and *01/01/1996*

 Thank you for your help
 Michel

 Also, in your example dataset:

 df1$contrat[grep(^CDD,df1$contrat)]
 #[1] CDD détaché ext. Cirad CDD détaché ext. Cirad CDD détaché ext. 
 Cirad
 #[4] CDD détaché ext. Cirad CDD détaché ext.Cirad  CDD détaché ext. 
 Cirad
 #[7] CDD détaché ext. Cirad CDD détaché ext.Cirad  CDD détaché ext. 
 Cirad
 ##Looks like there are extra spaces in some of them.  I guess these are the 
 same
 df1$contrat[grep(^CDD,df1$contrat)]- CDD détaché ext. Cirad


 I tried this:
 indx-as.numeric(interaction(df1[,1:6],drop=FALSE))

df1New- df1
 res2-unique(within(df1New,{Debut-ave(seq_along(indx),indx,FUN=function(x) 
 Debut[head(x,1)]);Fin- ave(seq_along(indx),indx,FUN=function(x) 
 Fin[tail(x,1)])}))
row.names(res2)- 1:nrow(res2)

 res2[,c(1,2,7:8)]
  MatriculeNom  DebutFin
 1  1  VERON 24/01/1995 31/12/1997
 2  6 BENARD 02/02/1995 12/03/1995
 3  6 BENARD 13/03/1995 31/01/1996 ###here not correct
 4  8 DALNIC 24/01/1995 31/08/1995
 5  8 DALNIC 01/09/1995 29/02/2000
 6934  FORNI 26/01/1995 31/08/2001
 7934  FORNI 01/09/2001 31/08/2004
 8934  FORNI 01/09/2004 31/08/2007
 9934  FORNI 01/09/2007 04/09/2012
 10   934  FORNI 05/09/2012 31/12/4712


 df2[,c(1,2,7:8)]
  MatNom  DebutFin
 11  VERON 24/01/1995 31/12/1997
 26 BENARD 02/02/1995 12/03/1995
 36 BENARD 13/03/1995 30/06/1995
 46 BENARD 01/01/1996 31/01/1996 #missing this row
 58 DALNIC 24/01/1995 31/08/1995
 68 DALNIC 01/09/1995 29/02/2000
 7  934  FORNI 26/01/1995 31/08/2001
 8  934  FORNI 01/09/2001 31/08/2004
 9  934  FORNI 01/09/2004 31/08/2007
 10 934  FORNI 01/09/2007 04/09/2012
 11 934  FORNI 05/09/2012 31/12/4712


 Here, the dates look similar to the ones on df2 except for one row in df2.

 A.K.




 - Original Message -
 From: Arnaud Michel michel.arn...@cirad.fr
 To: R help r-help@r-project.org
 Cc:
 Sent: Friday, July 12, 2013 3:45 PM
 Subject: [R] simplify a dataframe

 Hello

 I have the following problem : group the lines of a dataframe when no
 information change (Matricule, Nom, Sexe, DateNaissance, Contrat, Pays)
 and when the value of Debut of lines i = value Fin of lines i-1
 I can obtain it with a do loop. Is it possible to avoid the loop ?

 The dataframe initial is df1
 dput(df1)
 structure(list(Matricule = c(1L, 1L, 1L, 6L, 6L, 6L, 6L, 6L,
 6L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 934L, 934L, 934L, 934L,
 934L

Re: [R] simplify a dataframe

2013-07-14 Thread Arnaud Michel

Super !!!
Thank you very much Arun
Michel
Le 15/07/2013 03:47, arun a écrit :

HI Michel,
This gives the same order as that of df2.
df1$contrat[grep(^CDD,df1$contrat)]- CDD détaché ext. Cirad
df1[48,8]- 31/12/2013
indx-as.numeric(interaction(df1[,1:6],drop=TRUE))
lst1-split(df1,indx)
  lst2-lst1[match(unique(indx),names(lst1))]
res-do.call(rbind,lapply(lst2,function(x){x1- as.Date(x$Debut,format=%d/%m/%Y);x2- 
as.Date(x$Fin,format=%d/%m/%Y);do.call(rbind,lapply(split(x,cumsum(c(FALSE,(x1[-1]-x2[-nrow(x)])!=1))),function(x)
 data.frame(x[1,1:6],Debut=head(x$Debut,1),Fin=tail(x$Fin,1),stringsAsFactors=FALSE)))}))
  row.names(res)- 1:nrow(res)
  df2[11,8]- 31/12/2013
  names(res)[1]- Mat
  identical(res,df2)
#[1] TRUE


A.K.



- Original Message -
From: arun smartpink...@yahoo.com
To: Arnaud Michel michel.arn...@cirad.fr
Cc: R help r-help@r-project.org
Sent: Sunday, July 14, 2013 2:39 PM
Subject: Re: [R] simplify a dataframe

Hi,
May be this helps you.
df1$contrat[grep(^CDD,df1$contrat)]- CDD détaché ext. Cirad
df1[48,8]
[1] 31/12/4712 #strange value

df1[48,8]- 31/12/2013  #changed

indx-as.numeric(interaction(df1[,1:6],drop=TRUE))
res-do.call(rbind,lapply(split(df1,indx),function(x) {x1- 
as.Date(x$Debut,format=%d/%m/%Y);x2- 
as.Date(x$Fin,format=%d/%m/%Y);do.call(rbind,lapply(split(x,cumsum(c(FALSE,(x1[-1]-x2[-nrow(x)])!=1))),function(x)
 data.frame(x[1,1:6],Debut=head(x$Debut,1),Fin=tail(x$Fin,1),stringsAsFactors=FALSE)))}))

  res[order(res$Matricule),]  #the order of rows is a bit different than df2.
 MatriculeNom Sexe DateNaissancecontratPays
5   1  VERON  Féminin02/09/1935 CDI commun  France
4.0 6 BENARD Masculin01/04/1935 CDI commun  France
4.1 6 BENARD Masculin01/04/1935 CDI commun  France
10  6 BENARD Masculin01/04/1935 CDI commun Philippines
6   8 DALNIC  Féminin19/02/1940 CDI commun  France
9   8 DALNIC  Féminin19/02/1940 CDI commun  Martinique
1 934  FORNI Masculin10/07/1961 CDD détaché ext. CiradCameroun
2 934  FORNI Masculin10/07/1961 CDI commun   Congo
3 934  FORNI Masculin10/07/1961CDI Détachés Autres   Congo
7 934  FORNI Masculin10/07/1961CDI Détachés Autres  France
8 934  FORNI Masculin10/07/1961 CDI commun   Gabon
  DebutFin
5   24/01/1995 31/12/1997
4.0 13/03/1995 30/06/1995
4.1 01/01/1996 31/01/1996
10  02/02/1995 12/03/1995
6   24/01/1995 31/08/1995
9   01/09/1995 29/02/2000
1   26/01/1995 31/08/2001
2   05/09/2012 31/12/2013
3   01/09/2004 31/08/2007
7   01/09/2001 31/08/2004
8   01/09/2007 04/09/2012


A.K.




From: Arnaud Michel michel.arn...@cirad.fr
To: arun smartpink...@yahoo.com
Cc: R help r-help@r-project.org; jholt...@gmail.com; Rui Barradas 
ruipbarra...@sapo.pt
Sent: Sunday, July 14, 2013 12:17 PM
Subject: Re: [R] simplify a dataframe



Hi,
Excuse me for the indistinctness

Le 13/07/2013 17:18, arun a écrit :

Hi,
when the value of Debut of lines i = value Fin of lines i-1
That part is not clear esp. when it is looked upon with the expected output 
(df2).
I want to group the lines which have the same caracteristics (Matricule, Nom, 
Sexe, DateNaissance, Contrat, Pays) and with period of time (Debut/start and 
Fin/end) without interruption of time.
For exemple :
The following three lines
 :
 Debut/Start  Fin/End
1  VERON  Féminin02/09/1935 CDI commun  France 24/01/1995 
30/04/1997
1  VERON  Féminin02/09/1935 CDI commun  France
 01/05/1997 30/12/1997
1  VERON  Féminin02/09/1935 CDI commun  France
 31/12/1997 31/12/1997
are transformed into 1 line
1  VERON  Féminin02/09/1935 CDI commun  France 24/01/1995 
31/12/1997
because same caracteristicsand period of time without interruption
 of time (from 24/01/1995 to 31/12/1997)

The following six lines :
6 BENARD Masculin01/04/1935 CDI commun Philippines 02/02/1995 
27/02/1995
6 BENARD Masculin01/04/1935 CDI commun Philippines
 28/02/1995 28/02/1995
6 BENARD Masculin01/04/1935 CDI commun Philippines
 01/03/1995 12/03/1995
6 BENARD Masculin01/04/1935 CDI commun  France 13/03/1995 
30/06/1995
6 BENARD Masculin01/04/1935 CDI commun  France 01/01/1996 
30/01/1996
6 BENARD Masculin01/04/1935 CDI commun  France
 31/01/1996 31/01/1996
are transformed into
6 BENARD Masculin01/04/1935 CDI commun Philippines 02/02/1995 
12/03/1995
6 BENARD Masculin01/04/1935 CDI commun  France 13/03/1995 
30/06/1995
6 BENARD Masculin01/04/1935 CDI commun  France 01/01/1996 
31/01/1996
because
lines 1-3 identical

[R] simplify a dataframe

2013-07-12 Thread Arnaud Michel

Hello

I have the following problem : group the lines of a dataframe when no 
information change (Matricule, Nom, Sexe, DateNaissance, Contrat, Pays) 
and when the value of Debut of lines i = value Fin of lines i-1

I can obtain it with a do loop. Is it possible to avoid the loop ?

The dataframe initial is df1
dput(df1)
structure(list(Matricule = c(1L, 1L, 1L, 6L, 6L, 6L, 6L, 6L,
6L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L), Nom = c(VERON, VERON, VERON, BENARD,
BENARD, BENARD, BENARD, BENARD, BENARD, DALNIC, DALNIC,
DALNIC, DALNIC, DALNIC, DALNIC, DALNIC, DALNIC, DALNIC,
FORNI, FORNI, FORNI, FORNI, FORNI, FORNI, FORNI,
FORNI, FORNI, FORNI, FORNI, FORNI, FORNI, FORNI,
FORNI, FORNI, FORNI, FORNI, FORNI, FORNI, FORNI,
FORNI, FORNI, FORNI, FORNI, FORNI, FORNI, FORNI,
FORNI, FORNI), Sexe = c(Féminin, Féminin, Féminin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Féminin, Féminin, Féminin, Féminin, Féminin, Féminin,
Féminin, Féminin, Féminin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin, Masculin, Masculin, Masculin,
Masculin, Masculin, Masculin), DateNaissance = c(02/09/1935,
02/09/1935, 02/09/1935, 01/04/1935, 01/04/1935, 01/04/1935,
01/04/1935, 01/04/1935, 01/04/1935, 19/02/1940, 19/02/1940,
19/02/1940, 19/02/1940, 19/02/1940, 19/02/1940, 19/02/1940,
19/02/1940, 19/02/1940, 10/07/1961, 10/07/1961, 10/07/1961,
10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961,
10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961,
10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961,
10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961,
10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961, 10/07/1961,
10/07/1961, 10/07/1961), contrat = c(CDI commun, CDI commun,
CDI commun, CDI commun, CDI commun, CDI commun, CDI commun,
CDI commun, CDI commun, CDI commun, CDI commun, CDI commun,
CDI commun, CDI commun, CDI commun, CDI commun, CDI commun,
CDI commun, CDD détaché ext. Cirad, CDD détaché ext. Cirad,
CDD détaché ext. Cirad, CDD détaché ext. Cirad, CDD détaché ext. 
Cirad,
CDD détaché ext. Cirad, CDD détaché ext. Cirad, CDD détaché ext. 
Cirad,

CDD détaché ext. Cirad, CDI Détachés Autres, CDI Détachés Autres,
CDI Détachés Autres, CDI Détachés Autres, CDI Détachés Autres,
CDI Détachés Autres, CDI Détachés Autres, CDI Détachés Autres,
CDI Détachés Autres, CDI Détachés Autres, CDI Détachés Autres,
CDI Détachés Autres, CDI Détachés Autres, CDI commun, CDI commun,
CDI commun, CDI commun, CDI commun, CDI commun, CDI commun,
CDI commun), Pays = c(France, France, France, Philippines,
Philippines, Philippines, France, France, France, France,
France, Martinique, Martinique, Martinique, Martinique,
Martinique, Martinique, Martinique, Cameroun, Cameroun,
Cameroun, Cameroun, Cameroun, Cameroun, Cameroun, Cameroun,
Cameroun, France, France, France, France, France,
France, France, Congo, Congo, Congo, Congo, Congo,
Congo, Gabon, Gabon, Gabon, Gabon, Gabon, Gabon,
Congo, Congo), Debut = c(24/01/1995, 01/05/1997, 31/12/1997,
02/02/1995, 28/02/1995, 01/03/1995, 13/03/1995, 01/01/1996,
31/01/1996, 24/01/1995, 01/07/1995, 01/09/1995, 01/07/1997,
01/01/1998, 01/08/1998, 01/01/2000, 17/01/2000, 29/02/2000,
26/01/1995, 01/07/1996, 16/09/1997, 01/01/1998, 01/07/1998,
04/11/1999, 01/01/2001, 01/04/2001, 31/08/2001, 01/09/2001,
02/09/2001, 01/12/2001, 01/02/2003, 01/04/2003, 01/01/2004,
01/03/2004, 01/09/2004, 01/01/2005, 01/04/2005, 28/10/2006,
01/01/2007, 01/04/2007, 01/09/2007, 01/01/2009, 01/04/2009,
01/01/2010, 01/01/2011, 01/04/2011, 05/09/2012, 01/01/2013
), Fin = c(30/04/1997, 30/12/1997, 31/12/1997, 27/02/1995,
28/02/1995, 12/03/1995, 30/06/1995, 30/01/1996, 31/01/1996,
30/06/1995, 31/08/1995, 30/06/1997, 31/12/1997, 31/07/1998,
31/12/1999, 16/01/2000, 28/02/2000, 29/02/2000, 30/06/1996,
15/09/1997, 31/12/1997, 30/06/1998, 03/11/1999, 31/12/2000,
31/03/2001, 30/08/2001, 31/08/2001, 01/09/2001, 30/11/2001,
31/01/2003, 31/03/2003, 31/12/2003, 29/02/2004, 31/08/2004,
31/12/2004, 31/03/2005, 27/10/2006, 31/12/2006, 31/03/2007,
31/08/2007, 31/12/2008, 31/03/2009, 31/12/2009, 31/12/2010,
31/03/2011, 04/09/2012, 31/12/2012, 31/12/4712)), .Names = 
c(Matricule,

Nom, Sexe, DateNaissance, contrat, Pays, Debut, Fin
), class = data.frame, row.names = c(NA, -48L))

The dataframe to be obtained is df2
dput(df2)
structure(list(Mat = c(1L, 6L, 6L, 6L, 8L, 8L, 934L, 934L, 934L,
934L, 934L), Nom = c(VERON, BENARD, BENARD, BENARD, DALNIC,
DALNIC, FORNI, FORNI, FORNI, FORNI, FORNI), Sexe = c(Féminin,
Masculin, Masculin, Masculin, Féminin, Féminin, Masculin,
Masculin, Masculin, Masculin, Masculin), DateNaissance = 
c(02/09/1935,

01/04/1935, 01/04/1935, 01/04/1935, 

[R] To transform a dataframe

2013-06-29 Thread Arnaud Michel

Hello

I would like to transform the dataframe df1 into df2 (ie copy the data 
from several lines for a men/women to only one line by individu men/women)


dput(df1)
structure(list(Mat = c(934L, 934L, 934L, 935L, 935L, 936L, 936L,
936L, 936L, 937L, 937L, 937L, 937L), Nom = structure(c(2L, 2L,
2L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L), .Label = c(,
, , ), class = factor), Sexe = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = Masculin, 
class = factor),

Cat = c(6L, 7L, 8L, 7L, 8L, 6L, 7L, 8L, 9L, 3L, 4L, 6L, 7L
), Début = structure(c(5L, 7L, 2L, 12L, 8L, 3L, 4L, 10L,
11L, 13L, 1L, 6L, 9L), .Label = c(01/01/1990, 01/01/2011,
01/02/1986, 01/02/1990, 01/07/1986, 01/07/1993, 01/07/1994,
01/07/1996, 01/10/2003, 01/11/2002, 01/11/2011, 13/01/1986,
23/01/1986), class = factor), Fin = structure(c(2L, 9L,
10L, 3L, 10L, 5L, 6L, 7L, 10L, 8L, 1L, 4L, 10L), .Label = 
c(30/06/1993,

30/06/1994, 30/06/1996, 30/09/2003, 31/01/1990, 31/10/2002,
31/10/2011, 31/12/1989, 31/12/2010, 31/12/4712), class = 
factor)), .Names = c(Mat,
Nom, Sexe, Cat, Début, Fin), class = data.frame, row.names = 
c(NA,

-13L))


dput(df2)
structure(list(Mat = 934:937, Nom = structure(c(2L, 3L, 4L, 1L
), .Label = c(, , , ), class = factor),
Sexe = structure(c(1L, 1L, 1L, 1L), .Label = Masculin, class = 
factor),

Cat4 = c(NA, NA, NA, 4L), Début4 = structure(c(1L, 1L, 1L,
2L), .Label = c(, 01/01/1990), class = factor), Fin4 = 
structure(c(1L,

1L, 1L, 2L), .Label = c(, 30/06/1993), class = factor),
Cat5 = c(NA, NA, NA, NA), Début5 = c(NA, NA, NA, NA), Fin5 = c(NA,
NA, NA, NA), Cat6 = c(6L, NA, 6L, 6L), Début6 = structure(c(3L,
1L, 2L, 4L), .Label = c(, 01/02/1986, 01/07/1986, 01/07/1993
), class = factor), Fin6 = structure(c(2L, 1L, 4L, 3L), .Label = 
c(,

30/06/1994, 30/09/2003, 31/01/1990), class = factor),
Cat7 = c(7L, 7L, 7L, 7L), Début7 = structure(c(2L, 4L, 1L,
3L), .Label = c(01/02/1990, 01/07/1994, 01/10/2003,
13/01/1986), class = factor), Fin7 = structure(c(3L,
1L, 2L, 4L), .Label = c(30/06/1996, 31/10/2002, 31/12/2010,
31/12/4712), class = factor), Cat8 = c(8L, 8L, 8L, NA
), Début8 = structure(c(2L, 3L, 4L, 1L), .Label = c(, 01/01/2011,
01/07/1996, 01/11/2002), class = factor), Fin8 = structure(c(3L,
3L, 2L, 1L), .Label = c(, 31/10/2011, 31/12/4712), class = 
factor),

Cat9 = c(NA, NA, 9L, NA), Début9 = structure(c(1L, 1L, 2L,
1L), .Label = c(, 01/11/2011), class = factor), Fin9 = 
structure(c(1L,
1L, 2L, 1L), .Label = c(, 31/12/4712), class = factor)), 
.Names = c(Mat,

Nom, Sexe, Cat4, Début4, Fin4, Cat5, Début5, Fin5,
Cat6, Début6, Fin6, Cat7, Début7, Fin7, Cat8, Début8,
Fin8, Cat9, Début9, Fin9), class = data.frame, row.names = c(NA,
-4L))


Any idea ?
Thank you

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] a question to transform a dataframe empty 0/1

2013-06-20 Thread Arnaud Michel
Hello

I have the following dataframe :
df - data.frame(
Country=c(Zimbabwe,Burkina Faso,South Africa,Madagascar,Tanzania,
Mali,Mozambique,Madagascar,Ghana,Nigeria,Kenya,Burkina Faso,
  South Africa,Tanzania,Kenya,Ethiopia ) ,

Iso=c(ZW,BF,ZA,MG,TZ,ML,MZ,MG,GH,NG,KE,BF,
  ZA,TZ,KE,ET) ,

Abaco=c(1,0,1,1,0,1,0,0,0,0,1,1,0,0,0,0) ,
Adaptclone= c(0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0)
)
There is a lot of column like Abaco, Adaptclone,...
I would like to built a dataframe
wich transforms the initial dataframe of 4 columns into a dataframe of 3 
columns as the following dataframe

Country  IsoProject
Zimbabwe ZW Abaco
South Africa ZA Abaco
Madagascar   MG Abaco
Tanzania TZ Adaptclone
Mali ML Abaco
Mali ML Adaptclone
..

Any idea ?
Michel

-- 
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31


[[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.


Re: [R] a question to transform a dataframe empty 0/1

2013-06-20 Thread Arnaud Michel

Thank you arun !
I don't know the library reshape2
Michel

Le 20/06/2013 19:55, arun a écrit :

Hi,

Not sure if you wanted the entries with 0.

library(reshape2)
  dfMelt-melt(df,id.var=c(Country,Iso))

#subset those with 1

dfNew- subset(dfMelt,value==1,select=-4) row.names(dfNew)- 1:nrow(dfNew)
  dfNew
#Country Iso   variable
#1  Zimbabwe  ZW  Abaco
#2  South Africa  ZA  Abaco
#3Madagascar  MG  Abaco
#4  Mali  ML  Abaco
#5 Kenya  KE  Abaco
#6  Burkina Faso  BF  Abaco
#7  Tanzania  TZ Adaptclone
#8  Mali  ML Adaptclone
#9Mozambique  MZ Adaptclone
#10   Madagascar  MG Adaptclone
#11Ghana  GH Adaptclone
#12  Nigeria  NG Adaptclone


A.K.


Hello

I have the following dataframe :
df - data.frame(
Country=c(Zimbabwe,Burkina Faso,South Africa,Madagascar,Tanzania,
Mali,Mozambique,Madagascar,Ghana,Nigeria,Kenya,Burkina Faso,
   South Africa,Tanzania,Kenya,Ethiopia ) ,

Iso=c(ZW,BF,ZA,MG,TZ,ML,MZ,MG,GH,NG,KE,BF,
   ZA,TZ,KE,ET) ,

Abaco=c(1,0,1,1,0,1,0,0,0,0,1,1,0,0,0,0) ,
Adaptclone= c(0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0)
)
There is a lot of column like Abaco, Adaptclone,...
I would like to built a dataframe
wich transforms the initial dataframe of 4 columns into a dataframe of 3
columns as the following dataframe

Country  IsoProject
Zimbabwe ZW Abaco
South Africa ZA Abaco
Madagascar   MG Abaco
Tanzania TZ Adaptclone
Mali ML Abaco
Mali ML Adaptclone
..

Any idea ?
Michel



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] to build a data.frame

2013-06-19 Thread Arnaud Michel

Hello

I have the following dataframe

df - data.frame(
Project=c(Abaco,Abaco,Abac,Abaco,Abaco,Abaco,
Abaco,Adaptclone,Adaptclone,Adaptclone,Adaptclone,Adaptclone,
Adaptclone,Adopt,Adopt,Adopt),

Country=c(Zimbabwe,Burkina Faso,South Africa,Madagascar,Tanzania,
Mali,Mozambique,Madagascar,Ghana,Nigeria,Kenya,Burkina Faso,
 South Africa,Tanzania,Kenya,Ethiopia ),

Iso=c(ZW,BF,ZA,MG,TZ,ML,MZ,MG,GH,NG,KE,BF,
 ZA,TZ,KE,ET))

I would like to build a other dataframe with name Country
where column 1 is country,
the column 2 is number of project (in the country)
the column 3 is the code Iso (wich correspond with the country : Ex ZW 
is ISO of Zimbabwe)

  PaysPaysIso  NbrProj
   Zimbabwe  ZW   1
 Burkina FasoBF2


I know associate Country and Number of projets but how associate Iso

Any idea ?
Thank you for your help

--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.


[R] transform 3 numeric vectors empty of 0/1

2013-06-18 Thread Arnaud Michel

Dear all,
Without a loop, I would like transform 3 numeric vectors empty of 0/1 of 
same length

Vec1 : transform 1 to A and 0 to 
Vec2 : transform 1 to B and 0 to 
Vec3 : transform 1 to C and 0 to 
to obtain only 1 vector Vec who is the paste of the 3 vectors (Ex : ABC, 
BC, AC, AB,...)

Any idea ?
Thank you for your help

--
Michel ARNAUD

__
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.


[R] a title on the map (function gvisGeoChart package googleVis )

2013-06-11 Thread Arnaud Michel

Hi
I am using the package googleVis and the function gvisGeoChart
Is it possible to put a title on the map ?

Here is the call of the function :

library(googleVis)
G1 - gvisGeoChart(PaysProjets, locationvar='Pays', colorvar='NbProj',
options=list(
region= world,
displayMode=regions,
height=347*1.5, width= 556*1.5
))
plot(G1)
Thank you



--
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31

__
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.