[R] removing last element from a character string

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Aug 20 12:56:28 CEST 2004


Luis Rideau Cruz wrote:
> R-help,
> 
> Any function to remove last element (or any specific elemnet in the sequence) from a character string?
> 
> t<-c("aaab","qqqc")
> 
> 
>>function(t)  ### remove last character (b and c respectively)
> 
> 
>>aaa   qqq
> 


   substr(t, 1, nchar(t)-1)

Uwe Ligges


> Thanks
> 
> `·._ .·  `·. _ .·  `·._ .·  `·. _ .·  `·._ .·  `·. _ .·  `·..
> Luis Ridao Cruz
> Fiskirannsóknarstovan
> Nóatún 1
> P.O. Box 3051
> FR-110 Tórshavn
> Faroe Islands
> Phone:             +298 353900
> Phone(direct): +298 353912
> Mobile:             +298 580800
> Fax:                 +298 353901
> E-mail:              luisr at frs.fo
> Web:                www.frs.fo
> 
> `·._ .·  `·. _ .·  `·._ .·  `·. _ .·  `·._ .·  `·. _ .·  `·..
> 
> ______________________________________________
> R-help at 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




More information about the R-help mailing list