"Biedermann, Jürgen"
2009-Sep-08 14:23 UTC
[R] Count number of different patterns (Polytomous variable)
Hi there, Does anyone know a method to calculate the number of different patterns in a given data frame. The variables are of polytomous type and not binary (for the latter i found a package called "countpattern" which unfortunately only functions for binary variables). V1 V2 V3 0 3 1 1 2 0 1 2 0 So, in this case, i would like to get "2" as output. Thanks in advance J?rgen
Dimitris Rizopoulos
2009-Sep-08 17:28 UTC
[R] Count number of different patterns (Polytomous variable)
try this: DF <- data.frame(V1 = c(0,1,1), V2 = c(3,2,2), V2 = c(1,0,0)) DF nrow(unique(DF)) I hope it helps. Best, Dimitris Biedermann, J?rgen wrote:> Hi there, > > Does anyone know a method to calculate the number of different patterns > in a given data frame. The variables are of polytomous type and not > binary (for the latter i found a package called "countpattern" which > unfortunately only functions for binary variables). > > V1 V2 V3 > 0 3 1 > 1 2 0 > 1 2 0 > > So, in this case, i would like to get "2" as output. > > Thanks in advance > J?rgen > > ______________________________________________ > 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
jim holtman
2009-Sep-08 17:29 UTC
[R] Count number of different patterns (Polytomous variable)
try this:> xV1 V2 V3 1 0 3 1 2 1 2 0 3 1 2 0> unique(x)V1 V2 V3 1 0 3 1 2 1 2 0> nrow(unique(x))[1] 2>2009/9/8 "Biedermann, J?rgen" <juergen.biedermann at charite.de>:> Hi there, > > Does anyone know a method to calculate the number of different patterns in a > given data frame. The variables are of polytomous type and not binary (for > the latter i found a package called "countpattern" which unfortunately only > functions for binary variables). > > V1 ? V2 ? V3 > 0 ? 3 ? 1 > 1 ? 2 ? 0 > 1 ? 2 ? 0 > > So, in this case, i would like to get "2" as output. > > Thanks in advance > J?rgen > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Erik Iverson
2009-Sep-08 17:33 UTC
[R] Count number of different patterns (Polytomous variable)
If your data.frame was called "test" below, nrow(unique(test)) would do what you want, I believe. Erik -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of "Biedermann, J?rgen" Sent: Tuesday, September 08, 2009 9:24 AM To: r-help at r-project.org Subject: [R] Count number of different patterns (Polytomous variable) Hi there, Does anyone know a method to calculate the number of different patterns in a given data frame. The variables are of polytomous type and not binary (for the latter i found a package called "countpattern" which unfortunately only functions for binary variables). V1 V2 V3 0 3 1 1 2 0 1 2 0 So, in this case, i would like to get "2" as output.
Jorge Ivan Velez
2009-Sep-08 17:36 UTC
[R] Count number of different patterns (Polytomous variable)
Dear Jürgen, If x is your data, here are two suggestions: # Suggestion 1 length(unique( apply(x, 1, paste, sep="", collapse="") ) ) # [1] 2 # Suggestion 2 res <- as.data.frame( xtabs( ~. , as.data.frame( x ) ) ) dim(res[res$Freq > 0,])[1] # [1] 2 HTH, Jorge 2009/9/8 "Biedermann, Jürgen" <juergen.biedermann@charite.de>> Hi there, > > Does anyone know a method to calculate the number of different patterns in > a given data frame. The variables are of polytomous type and not binary (for > the latter i found a package called "countpattern" which unfortunately only > functions for binary variables). > > V1 V2 V3 > 0 3 1 > 1 2 0 > 1 2 0 > > So, in this case, i would like to get "2" as output. > > Thanks in advance > Jürgen > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Seemingly Similar Threads
- How to use the paste function to create an already used variable
- cbind formula definition
- How to specify "newdata" in a Cox-Modell with a time dependent interaction term?
- help with polytomous logistic regression
- Define a glm object with user-defined coefficients (logistic regression, family="binomial")