[R] Is it possible to get the first letter of a word?
Hi, I would to get the first letter of a word like: title_cat TitleCat 1 Training I would like T from Training! Thnaks a lot for your help Sabine - Téléchargez le ici ! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Is it possible to get the first letter of a word?
Navarre Sabine wrote: Hi, I would to get the first letter of a word like: title_cat TitleCat 1 Training I would like T from Training! Thnaks a lot for your help substr(title_cat,1,1) Uwe Ligges Sabine - Téléchargez le ici ! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Is it possible to get the first letter of a word?
Use substring() or substr(). Andy From: Navarre Sabine Hi, I would to get the first letter of a word like: title_cat TitleCat 1 Training I would like T from Training! Thnaks a lot for your help Sabine - Téléchargez le ici ! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Is it possible to get the first letter of a word?
?substring Navarre Sabine wrote: Hi, I would to get the first letter of a word like: title_cat TitleCat 1 Training I would like T from Training! Thnaks a lot for your help Sabine - Téléchargez le ici ! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Is it possible to get the first letter of a word?
or What about; strsplit(Training, split=)[[1]][1] [1] T Ken Knoblauch Inserm U371, Cerveau et Vision Department of Cognitive Neurosciences 18 avenue du Doyen Lepine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: 06 84 10 64 10 http://www.lyon.inserm.fr/371/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Is it possible to get the first letter of a word?
On Wed, 2005-06-22 at 16:42 +0200, Navarre Sabine wrote: Hi, I would to get the first letter of a word like: title_cat TitleCat 1 Training I would like T from Training! Thnaks a lot for your help Sabine There are multiple approaches, but you need to be careful, since it appears that your object is a factor. Thus you may need to convert to a character vector first: title_cat - factor(Training) substr(as.character(title_cat), 1, 1) [1] T Otherwise: title_cat - Training substr(title_cat, 1, 1) [1] T See ?substr for more information. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html