An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090312/863ac0a6/attachment-0002.pl>
who can give me some hint?
6 messages · Simon Pickett, Richard Cotton, Gabor Grothendieck +1 more
Hi All,
act_2
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
55 2006-02-22 14:52:49 14 52 49 4
57 2006-02-22 14:52:51 14 52 51 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
I want to change act_2 to
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
in other word, I want to keep 1st if there are many repeated value, I made
the program as:
Not sure what you mean here, can you describe this more fully?
It seems that you might be able to avoid using loops if all you want to do
is select only the rows where column x is less than a threshold value.
e.g.
a<-a[a$columnx<1000,]
Hope this helps
Simon.
rm_r<-function(act_2){
dm<-dim(act_2)[1]-1
for(i in 2:dm){
if(act_2$Rep[i+1]==act_2$Rep[i]){
act_2<-act_2[-(i+1),]
}else{
act_2<-act_2
}
}
return(act_2)
}
when it moved one row on 1st loop, i should still start 2 but it become 3 at
2nd loop, if I add i<-i-1, then i go to 1
seems not reasonbale. How should I modify it`?
Tammy
_________________________________________________________________
Drag n' drop-Get easy photo sharing with Windows LiveT Photos.
http://www.microsoft.com/windows/windowslive/products/photos.aspx
--------------------------------------------------------------------------------
______________________________________________ R-help at 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.
Hi All,
act_2
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
55 2006-02-22 14:52:49 14 52 49 4
57 2006-02-22 14:52:51 14 52 51 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
I want to change act_2 to
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
in other word, I want to keep 1st if there are many repeated value,
I made the program as:
rm_r<-function(act_2){
dm<-dim(act_2)[1]-1
for(i in 2:dm){
if(act_2$Rep[i+1]==act_2$Rep[i]){
act_2<-act_2[-(i+1),]
}else{
act_2<-act_2
}
}
return(act_2)
}
when it moved one row on 1st loop, i should still start 2 but it
become 3 at 2nd loop, if I add i<-i-1, then i go to 1
seems not reasonbale. How should I modify it`?
Please don't repeatedly post the same question - it is irritating, and
you're not likely to get a favourable response. Try explaining your
problem more clearly. What is the condition that you want to use to keep
rows? (In your example, each of the rows is different, yet you kept some
and discarded others.)
If you just want to discard some rows form a data frame, you don't need a
loop, e.g.
dfr <- data.frame(x=1:10, y=runif(10))
dfr[c(1,3,5,5),]
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}
I assume the problem is to only keep those rows whose
Rep value is not equal to the Rep value in the prior row.
In that case just compare c("", Rep[-nr]) to Rep and
use the resulting vector, ix, to select out rows.
Rep <- as.character(act_2$Rep) could
be simplified to Rep <- act_2$Rep if Rep
is already known to be "character".
Lines <- "Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
55 2006-02-22 14:52:49 14 52 49 4
57 2006-02-22 14:52:51 14 52 51 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle"
act_2 <- read.table(textConnection(Lines), header = TRUE, as.is = TRUE)
nr <- nrow(act_2)
Rep <- as.character(act_2$Rep)
ix <- Rep != c("", Rep[-nr])
act_2[ix]
On Thu, Mar 12, 2009 at 6:25 AM, Tammy Ma <metal_licaling at live.com> wrote:
?Hi All,
act_2
? ? ? ? Date ? ?Dtime Hour Min Second ? ? ? ? ? ? ? Rep
51 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ?useractivity_act
52 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ? ? ? ? ? ? ? ? 4
55 2006-02-22 14:52:49 ? 14 ?52 ? ? 49 ? ? ? ? ? ? ? ? 4
57 2006-02-22 14:52:51 ? 14 ?52 ? ? 51 ? ? ? ? ? ? ? ? 4
58 2006-02-22 14:52:52 ? 14 ?52 ? ? 52 ? ? ? ? ? ? ? ? 3
60 2006-02-22 14:54:42 ? 14 ?54 ? ? 42 useractivity_idle
I want to change act_2 to
? ? ? ? Date ? ?Dtime Hour Min Second ? ? ? ? ? ? ? Rep
51 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ?useractivity_act
52 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ? ? ? ? ? ? ? ? 4
58 2006-02-22 14:52:52 ? 14 ?52 ? ? 52 ? ? ? ? ? ? ? ? 3
60 2006-02-22 14:54:42 ? 14 ?54 ? ? 42 useractivity_idle
in other word, I want to keep 1st if there are many repeated value, I made the program as:
rm_r<-function(act_2){
?dm<-dim(act_2)[1]-1
?for(i in 2:dm){
?if(act_2$Rep[i+1]==act_2$Rep[i]){
? act_2<-act_2[-(i+1),]
? }else{
? act_2<-act_2
? }
?}
return(act_2)
}
when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i<-i-1, then i go to 1
seems not reasonbale. How should I modify it`?
Tammy
_________________________________________________________________ Drag n? drop?Get easy photo sharing with Windows Live? Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx ? ? ? ?[[alternative HTML version deleted]] ______________________________________________ R-help at 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090312/3026501c/attachment-0002.pl>
Its not clear what "more flexible refers to". The posted solution already produces the sample output you showed. What else should it do?
On Thu, Mar 12, 2009 at 8:15 AM, Tammy Ma <metal_licaling at live.com> wrote:
Thanks a lot for your reply. I expect a more flexible solution. Because I couldn't check that column one by one. If another Rep colum is: useractivity_act 2 2 3 3 3 4 5 5 6 useractivity_idle i should be able to write a program to make it as: useractivity_act 2 3 4 5 6 useractivity_idle Only keep 1st value of repeated values. I have been working no it for a while....Still didnt get solution. Thanks for your concentration. Tammy
Date: Thu, 12 Mar 2009 08:03:11 -0400
Subject: Re: [R] who can give me some hint?
From: ggrothendieck at gmail.com
To: metal_licaling at live.com
CC: r-help at r-project.org
I assume the problem is to only keep those rows whose
Rep value is not equal to the Rep value in the prior row.
In that case just compare c("", Rep[-nr]) to Rep and
use the resulting vector, ix, to select out rows.
Rep <- as.character(act_2$Rep) could
be simplified to Rep <- act_2$Rep if Rep
is already known to be "character".
Lines <- "Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
55 2006-02-22 14:52:49 14 52 49 4
57 2006-02-22 14:52:51 14 52 51 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle"
act_2 <- read.table(textConnection(Lines), header = TRUE, as.is = TRUE)
nr <- nrow(act_2)
Rep <- as.character(act_2$Rep)
ix <- Rep != c("", Rep[-nr])
act_2[ix]
On Thu, Mar 12, 2009 at 6:25 AM, Tammy Ma <metal_licaling at live.com> wrote:
?Hi All,
act_2
? ? ? ? Date ? ?Dtime Hour Min Second ? ? ? ? ? ? ? Rep
51 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ?useractivity_act
52 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ? ? ? ? ? ? ? ? 4
55 2006-02-22 14:52:49 ? 14 ?52 ? ? 49 ? ? ? ? ? ? ? ? 4
57 2006-02-22 14:52:51 ? 14 ?52 ? ? 51 ? ? ? ? ? ? ? ? 4
58 2006-02-22 14:52:52 ? 14 ?52 ? ? 52 ? ? ? ? ? ? ? ? 3
60 2006-02-22 14:54:42 ? 14 ?54 ? ? 42 useractivity_idle
I want to change act_2 to
? ? ? ? Date ? ?Dtime Hour Min Second ? ? ? ? ? ? ? Rep
51 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ?useractivity_act
52 2006-02-22 14:52:18 ? 14 ?52 ? ? 18 ? ? ? ? ? ? ? ? 4
58 2006-02-22 14:52:52 ? 14 ?52 ? ? 52 ? ? ? ? ? ? ? ? 3
60 2006-02-22 14:54:42 ? 14 ?54 ? ? 42 useractivity_idle
in other word, I want to keep 1st if there are many repeated value, I
made the program as:
rm_r<-function(act_2){
?dm<-dim(act_2)[1]-1
?for(i in 2:dm){
?if(act_2$Rep[i+1]==act_2$Rep[i]){
? act_2<-act_2[-(i+1),]
? }else{
? act_2<-act_2
? }
?}
return(act_2)
}
when it moved one row on 1st loop, i should still start 2 but it become
3 at 2nd loop, if I add i<-i-1, then i go to 1
seems not reasonbale. How should I modify it`?
Tammy
_________________________________________________________________ Drag n? drop?Get easy photo sharing with Windows Live? Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx ? ? ? ?[[alternative HTML version deleted]] ______________________________________________ R-help at 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.
________________________________ Get news, entertainment and everything you care about at Live.com. Check it out!