[R] Unique values in dataframe columns

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Sep 26 07:34:36 CEST 2014

You messed up the quote marks and the "library" function is not capitalized. You defined your search list by the name "list", which is also the name of a commonly used base function in R. Also, the vector you gave to GetAllSubsets had several misleading invisible conversions to character because you concatenated various types together. This will in turn lead to more invisible conversions to character when testing of columns z and J occurs. Try using a decent text editor to create your email, and keep studying the Introduction to R document that comes with the software.

I don't know of a computationally efficient solution to this problem as you have described it, and with the type conversions going on I am not sure it is even possible to get a correct solution, but the code below is my attempt. I renamed your "list" to "lst".

  , function(x){
      tst <- function(x){all(x %in% y)}
    !is.na( Position( tst,lst ) )
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

On September 25, 2014 4:53:38 PM PDT, "Maicel Monzón Pérez" <maicel at infomed.sld.cu> wrote:
>Hello  list
>I would like to know how can  i detect  dataframe columns that have as
>unique values elements of a list.
>For example, at a  given dataframe to look for columns that unique
>are elements of a list like this one
>x = c("yes”, "1”, "no”, "no”),
>y = c("black”, "red”, "NA”, "white”),
>z= c(T,F,T,T),
>J= c(2,7,8,9))
>list<-GetAllSubsets(c(NA,0,1,2,"yes","y","no"),min.n = 2, max.n = 5)
>......and to obtain  the following vector..
>Best regards
>Maicel Monzon
>Nunca digas nunca, di mejor: gracias, permiso, disculpe.
>Este mensaje le ha llegado mediante el servicio de correo electronico
>que ofrece Infomed para respaldar el cumplimiento de las misiones del
>Sistema Nacional de Salud. La persona que envia este correo asume el
>compromiso de usar el servicio a tales fines y cumplir con las
>regulaciones establecidas
>Infomed: http://www.sld.cu/
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list