Dear R-list, Is there any way I can extract part or whole column name from two variables and combine them? Not values, but column names. For example, I have data set with 70 variables. The column names are "Alfalfa", "Corn","Soybean",..."Sunflower". After I combine the two variable (say Alfalfa and Corn), I want to rename it as "AlfCor" or "AlfalfaCorn" automatically not manually. In excel, I found the function combining two texts in individual columns using (=A1&B1, if you want to combine texts in the two cells.). Thank you very much in advance! Steve Hong 437 RUSSELL LAB. 1630 LINDEN DR. ENTOMOLOGY DEPT. MADISON, WI, 53706 Tel: 608-263-0964 Fax: 608-262-3322
combine column names
4 messages · Steve Hong, David Winsemius, Jorge Ivan Velez +1 more
On May 1, 2009, at 2:55 PM, SEUNG CHEON HONG wrote:
Dear R-list, Is there any way I can extract part or whole column name from two variables and combine them? Not values, but column names. For example, I have data set with 70 variables. The column names are "Alfalfa", "Corn","Soybean",..."Sunflower". After I combine the two variable (say Alfalfa and Corn), I want to rename it as "AlfCor" or "AlfalfaCorn" automatically not manually. In excel, I found the function combining two texts in individual columns using (=A1&B1, if you want to combine texts in the two cells.).
?paste ?colnames David Winsemius, MD Heritage Laboratories West Hartford, CT
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090501/ad43a66e/attachment-0001.pl>
Jorge Ivan Velez wrote:
Dear Seung, Try this:
Names <- letters[1:5] Names
[1] "a" "b" "c" "d" "e"
apply(t(combn(Names,2)), 1, paste, collapse="")
[1] "ab" "ac" "ad" "ae" "bc" "bd" "be" "cd" "ce" "de"
another option is to use the 'FUN' argument of combn(), e.g., combn(Names, 2, FUN = paste, collapse = "") Best, Dimitris
HTH, Jorge On Fri, May 1, 2009 at 2:55 PM, SEUNG CHEON HONG <sch at entomology.wisc.edu>wrote:
Dear R-list, Is there any way I can extract part or whole column name from two variables and combine them? Not values, but column names. For example, I have data set with 70 variables. The column names are "Alfalfa", "Corn","Soybean",..."Sunflower". After I combine the two variable (say Alfalfa and Corn), I want to rename it as "AlfCor" or "AlfalfaCorn" automatically not manually. In excel, I found the function combining two texts in individual columns using (=A1&B1, if you want to combine texts in the two cells.). Thank you very much in advance! Steve Hong 437 RUSSELL LAB. 1630 LINDEN DR. ENTOMOLOGY DEPT. MADISON, WI, 53706 Tel: 608-263-0964 Fax: 608-262-3322
______________________________________________ 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.
[[alternative HTML version deleted]]
______________________________________________ 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