Skip to content

frequency

3 messages · Farnoosh Sheikhi, arun

#
Hi,
Try this:
dat1<-read.table(text="
ID??? Visit
x a1
x a2
x a2
x a1
x a1
y b1
y c23
y b33
",sep="",header=TRUE,stringsAsFactors=FALSE) 
cn1<-count(dat1[!duplicated(dat1),]$ID)
colnames(cn1)<-c("ID","response")
merge(dat1,cn1,by="ID",all=TRUE)
#ID Visit response
#1? x??? a1??????? 2
#2? x??? a2??????? 2
#3? x??? a2??????? 2
#4? x??? a1??????? 2
#5? x??? a1??????? 2
#6? y??? b1??????? 3
#7? y?? c23??????? 3
#8? y?? b33??????? 3
A.K.
#
Hi Farnoosh,

Sorry, it's in library(plyr)
If you don't want to install plyr,
then, you can use ?table()
dat1<-read.table(text="
ID??? Visit
x a1
x a2
x a2
x a1
x a1
y b1
y c23
y b33
",sep="",header=TRUE,stringsAsFactors=FALSE) 

cn2<-data.frame(table(dat1[!duplicated(dat1),]$ID))
?colnames(cn2)<-c("ID","response")
?merge(dat1,cn2,by="ID",all=TRUE)
? ID Visit response
1? x??? a1??????? 2
2? x??? a2??????? 2
3? x??? a2??????? 2
4? x??? a1??????? 2
5? x??? a1??????? 2
6? y??? b1??????? 3
7? y?? c23??????? 3
8? y?? b33??????? 3



A.K.