[R] creating character vector
Eik Vettorazzi
E.Vettorazzi at uke.uni-hamburg.de
Mon Mar 14 20:12:13 CET 2011
Hi Jim,
this may be barking up the wrong tree, but
create <-function(...) paste(substitute(list(...)))[-1]
createl <-function(...) {
tmp<-list(...)
names(tmp)<-create(...)
tmp
}
#eg
a<-1:4
b<-letters[2:6]
createl(a,b)
works. But I can't imagine that a named list is the one and only useful
data type for your problem.
Am 14.03.2011 19:36, schrieb Maas James Dr (MED):
> Nice simple elegant solution .... care to have a crack at this one ...!!
>
> Thanks for help and answer!
>
> Jim
>
> In a parallel routine using foreach and doMPI have to put calculated values into a list of lists such as
>
> list(one=one,
> two=two,
> three=three)
>
> It uses the same (large) list of variable names as in the previous question. Is there a simpler way to accomplish this with a lapply statement?
>
>
> I've tried several permutations but no luck!
>
>
> ===============================
> Dr. Jim Maas
> University of East Anglia
>
> From: Eik Vettorazzi [E.Vettorazzi at uke.uni-hamburg.de]
> Sent: 14 March 2011 18:07
> To: Maas James Dr (MED)
> Cc: r-help at r-project.org
> Subject: Re: [R] creating character vector
>
> Hi Jim
>
> create <-function(...) paste(substitute(list(...)))[-1]
>
> create(a,b,c)
>
> should work.
>
> hth.
>
> Am 14.03.2011 10:29, schrieb Maas James Dr (MED):
>> Is there a way to convince R to create a character vector without using the quotes?
>>
>> This works
>>
>> ex1 <- c("first","second")
>>
>> but when I try this it doesn't
>>
>> ext <- as.character(c(first,second))
>>
>> it complains. I have many variables to put into character vectors so dispensing with the quotes would be useful.
>>
>> Thanks
>>
>> Jim
>>
>>
>> ===============================
>> Dr. Jim Maas
>> University of East Anglia
>>
>>
>> [[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.
>
> --
> Eik Vettorazzi
> Institut für Medizinische Biometrie und Epidemiologie
> Universitätsklinikum Hamburg-Eppendorf
>
> Martinistr. 52
> 20246 Hamburg
>
> T ++49/40/7410-58243
> F ++49/40/7410-57790
--
Eik Vettorazzi
Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
More information about the R-help
mailing list