Dear All, Could anyone suggest a quick way to combine all columns in a data frame into a vector? For example, I have a data frame of 205 columns with character data types, many data values are repeated in all the columns. Actually, I would like to retrieve all the unique values from this data set. My strategy is to put all column value into a vector and then select unique from that vector. I would appreciate a more efficient method. Thanks. -Sohail The information contained in this electronic e-mail transmission and any attachments are intended only for the use of the individual or entity to whom or to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this communication is not the intended recipient, or the employee or agent responsible for delivering this communication to the intended recipient, you are hereby notified that any dissemination, distribution, copying or disclosure of this communication and any attachment is strictly prohibited. If you have received this transmission in error, please notify the sender immediately by telephone and electronic mail, and delete the original communication and any attachment from any computer, server or other electronic recording or storage device or medium. Receipt by anyone other than the intended recipient is not a waiver of any attorney-client, physician-patient or other privilege.
Sohail: 1. Are they character or factor? 2. ?unlist> unique(unlist(yourframe))-- Bert On Mon, Aug 12, 2013 at 1:23 PM, Khan, Sohail <SKhan30 at nshs.edu> wrote:> Dear All, > > Could anyone suggest a quick way to combine all columns in a data frame into a vector? > For example, I have a data frame of 205 columns with character data types, many data values are repeated in all the columns. Actually, I would like to retrieve all the unique values from this data set. My strategy is to put all column value into a vector and then select unique from that vector. > > I would appreciate a more efficient method. > Thanks. > -Sohail > > > The information contained in this electronic e-mail transmission and any attachments are intended only for the use of the individual or entity to whom or to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this communication is not the intended recipient, or the employee or agent responsible for delivering this communication to the intended recipient, you are hereby notified that any dissemination, distribution, copying or disclosure of this communication and any attachment is strictly prohibited. If you have received this transmission in error, please notify the sender immediately by telephone and electronic mail, and delete the original communication and any attachment from any computer, server or other electronic recording or storage device or medium. Receipt by anyone other than the intended recipient is not a waiver of any attorney-client, physician-patient or other priv! > ilege. > ______________________________________________ > 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Hi, May be this help: dat1<- structure(list(V1 = c("h", "f", "s", "n", "r", "x", "h", "t", "u", "g"), V2 = c("p", "j", "r", "r", "i", "x", "f", "b", "n", "d"), V3 = c("c", "o", "s", "d", "f", "r", "b", "p", "q", "b" ), V4 = c("i", "g", "j", "d", "y", "f", "s", "q", "s", "z"), ??? V5 = c("m", "j", "h", "f", "b", "b", "k", "j", "g", "i"), ??? V6 = c("m", "w", "m", "s", "o", "z", "l", "h", "e", "d"), ??? V7 = c("m", "g", "h", "d", "s", "i", "y", "z", "t", "m"), ??? V8 = c("d", "f", "a", "z", "q", "i", "o", "v", "a", "s"), ??? V9 = c("n", "d", "n", "f", "j", "j", "g", "w", "k", "v"), ??? V10 = c("i", "t", "y", "c", "m", "p", "q", "c", "k", "m")), .Names = c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10"), row.names = c(NA, -10L), class = "data.frame") unique(unlist(dat1)) # [1] "h" "f" "s" "n" "r" "x" "t" "u" "g" "p" "j" "i" "b" "d" "c" "o" "q" "y" "z" #[20] "m" "k" "w" "l" "e" "a" "v" #or unique(as.vector(as.matrix(dat1))) # [1] "h" "f" "s" "n" "r" "x" "t" "u" "g" "p" "j" "i" "b" "d" "c" "o" "q" "y" "z" #[20] "m" "k" "w" "l" "e" "a" "v" A.K. ----- Original Message ----- From: "Khan, Sohail" <SKhan30 at nshs.edu> To: 'greatest.possible.newbie' <daniel.hoop at gmx.net>; "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Monday, August 12, 2013 4:23 PM Subject: [R] combine all data frame columns into a vector. Dear All, Could anyone suggest a quick way to combine all columns in a data frame into a vector? For example, I have a data frame of 205 columns with character data types, many data values are repeated in all the columns.? Actually, I would like to retrieve all the unique values from this data set.? My strategy is to put all column value into a vector and then select unique from that vector. I would appreciate a more efficient method. Thanks. -Sohail The information contained in this electronic e-mail transmission and any attachments are intended only for the use of the individual or entity to whom or to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this communication is not the intended recipient, or the employee or agent responsible for delivering this communication to the intended recipient, you are hereby notified that any dissemination, distribution, copying or disclosure of this communication and any attachment is strictly prohibited. If you have received this transmission in error, please notify the sender immediately by telephone and electronic mail, and delete the original communication and any attachment from any computer, server or other electronic recording or storage device or medium. Receipt by anyone other than the intended recipient is not a waiver of any attorney-client, physician-patient or other priv! ilege. ______________________________________________ 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.