Or try this : x1=c(1,1,0,0,0,1,0) x2=c(1,0,1,1,0,1,1)
DF=cbind(x1,x2) ifelse(DF[,1]==DF[,2],1,0) your n1 is : sum(ifelse(DF[,1]==DF[,2],1,0)) your n2 is : dim(DF)[1]-sum(ifelse(DF[,1]==DF[,2],1,0)) Maybe not an elegant way, but hope this help. Julien GRASSOT Data Analysis Department Flamel Technologies FRANCE -----Message d'origine----- De : r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] De la part de Henrique Dallazuanna Envoyé : mardi 13 octobre 2009 14:41 À : Ashta Cc : R help Objet : Re: [R] Counting Try this: table(Reduce(`==`, DF)) On Tue, Oct 13, 2009 at 9:20 AM, Ashta <sewa...@gmail.com> wrote: > *Hi all, > * > > *Assume that I have the following data set with tow variables and I want > count the number of observation with identical values > * > > ** > > *x1 x2* > > * 1 1 * > > * 1 0 * > > * 0 1* > > * 0 1* > > * 0 0* > > * 1 1* > > * 0 1 > * > > > I want the following output > ** > > * > * > > *n1=3 # number of identical observation between x1 and x2 variables* > > *n2=4 # number of different observation* > > > How do I do it in R? > > > Thanks a lot > > > > > ** > > [[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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ 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-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.