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
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
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,
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
.
- 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
: [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
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
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
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
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
, 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
Here is how you can do it with the 'data.table' package:
require(data.table)
df1 - data.table(df1)
result - df1[
+ , list(Debut = Debut[1L] # first entry
+ , Fin = Fin[1L]
+ )
+ , keyby = c(Matricule, Nom, Sexe, DateNaissance, contrat,
Pays)
+ ]
result
MatriculeNom Sexe
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
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
Hello,
My solution is missing a row, but maybe you can find some inspiration.
cols - c(Matricule, Nom, Sexe, DateNaissance, contrat, Pays)
irow1 - duplicated(df1[, cols])
irow2 - c(FALSE, df1$Debut[-1] == df1$Fin[-nrow(df1)])
df3 - df1[!irow1 !irow2, ]
dim(df2); dim(df3) # df3 has one row
15 matches
Mail list logo