[R] String question

Gustaf Rydevik gustaf.rydevik at gmail.com
Wed Dec 23 13:18:54 CET 2009


On Wed, Dec 23, 2009 at 11:21 AM, Knut Krueger <rh at krueger-family.de> wrote:
> Hi to all
>
> I need a string like
> temp <- paste("m1","m2","m3",sep=",")
> But i must know how many items are in the string,afterwards
> the other option would be to use a vector
> temp <- c("m1","m2","m3")
> No problem to get the count of items but I must get afterwards the string
>  "m1,m2,m3"
> No problem to build the string with a loop, but it should be more easy but
> it seems that I am looking to the wrong functions.
>
> Kind regards Knut
>

Just thought I'd show you a solution from the other direction, in
addition to those that all other have posted:


temp <- paste("m1","m2","m3",sep=",")##Generate string
nchar(gsub("([^,])","",temp))+1## Count commas in the string and add 1.


Regards,
Gustaf

-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik




More information about the R-help mailing list