[R] String manipulation
spencer.graves at pdf.com
Fri Jun 25 11:33:23 CEST 2004
Does the following do what you want (or supply the missing gaps):
> Args <- paste(c("female", "male"), "= names", 1:2, sep="")
 "female= names1" "male= names2"
> listText <- paste("names.list<-list(",
+ paste(Args, collapse=","), ")")
 "names.list<-list( female= names1,male= names2 )"
> names1 <- c("Sue", "Betty")
> names2 <- c("Bill", "Sam")
 "Sue" "Betty"
 "Bill" "Sam"
hope this helps. spencer graves
p.s. "str" is the name of a function to "Compactly Display the
Structure of an Arbitrary R Object". I prefer to avoid masking
functions with local objects, even though R can tell which object is
desired in many but not all contexts. To avoid this, I often test a
name before I use it. When I don't get, "Object ... not found", I try
something different, e.g., using capital letters somewhere or adding a
"." at the end. This also has the advantage of introducing me or
reminding me of functions I may not have known.
Robin Gruna wrote:
>let's see, if someone can help my with this one:
>I have the string as follows:
>Now I want to concatenate the items to one string, seperateted by space or
>>"one, two, three"
>If possible without a loop.
>My actual goal ist to create string like
>>"female = names1, male = names2"
>and pass it as argument to list(), intending to create a list
>>names.list<-list( female = names1, male = names2)
>Thanks a lot,
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help