Hi,
You can use ?split()
lst1<-split(DF,DF$ID)
lst1[1:2]
#$`1`
# ID drugs month
#1 1 drug x 1
#4 1 drug x 1
#5 1 drug y 2
#6 1 drug z 3
#
#$`2`
# ID drugs month
#2 2 drug y 2
#7 2 drug x 1
mean(sapply(lst1,nrow))
#[1] 2.4
#or
library(plyr)
mean(ddply(DF,.(ID),
select the
dataframe rows which do not contain particular IDs say for example IDs 2 and 5
in this case.
Thanks again for your time
Rith
From: Peter Ehlers
To: steven mosher
org>
Sent: Wed, December 15, 2010 3:26:14 AM
Subject: Re: [R] selecting certain rows fr
lers
Thanks again for your time
Rith
*From:* Peter Ehlers
*To:* steven mosher
*Cc:* Hrithik R ; "r-help@r-project.org"
*Sent:* Wed, December 15, 2010 3:26:14 AM
*Subject:* Re: [R] selecting certain rows from data frame
On 2010-12-14 23:57, ste
select the
dataframe rows which do not contain particular IDs say for example IDs 2 and 5
in this case.
Thanks again for your time
Rith
From: Peter Ehlers
To: steven mosher
org>
Sent: Wed, December 15, 2010 3:26:14 AM
Subject: Re: [R] selecting certain rows fr
On Dec 15, 2010, at 4:18 AM, Ivan Calandra wrote:
Hi,
Just to note that which() is unnecessary here:
DF2 <- DF[DF$ID==2 | DF$ID==5, ]
And to further note that it is only unnecessary of you have no NA's in
that ID column.
> DF[4,1] <- NA
> DF[8,1] <- NA
> DF2 <- DF[DF$ID==2 | DF$ID==5, ]
Hi,
Just to note that which() is unnecessary here:
DF2 <- DF[DF$ID==2 | DF$ID==5, ]
Ivan
Le 12/15/2010 08:57, steven mosher a écrit :
Hi,
Next time give folks code to produce a toy sample of your problem
DF<-data.frame(ID=rep(1:5,each=3),Data=rnorm(15),Stuff=seq(1:15))
DF
ID Da
On 2010-12-14 23:57, steven mosher wrote:
Hi,
Next time give folks code to produce a toy sample of your problem
DF<-data.frame(ID=rep(1:5,each=3),Data=rnorm(15),Stuff=seq(1:15))
DF
ID Data Stuff
1 1 2.0628225 1
2 1 0.6599165 2
3 1 0.5672595 3
4 2 -0.5308823
Hi,
Next time give folks code to produce a toy sample of your problem
DF <-data.frame(ID=rep(1:5,each=3),Data=rnorm(15),Stuff=seq(1:15))
DF
ID Data Stuff
1 1 2.0628225 1
2 1 0.6599165 2
3 1 0.5672595 3
4 2 -0.5308823 4
5 2 -0.5358471 5
6 2 -0.1414992
Hi,
if I have a dataframe such that
ID Time Earn
1 1 10
1 2 50
1 3 68
2 1 40
2 2 78
24 88
3 1 50
3 2 60
3 3 98
4 1 33
4 2 48
44
9 matches
Mail list logo