Thanks to Justin, Baptiste, and Sebed for your answers.
The solutions work well. I have been putting them to good use today: the
code now works wonderfully and I learnt some useful tricks!

thanks, Peter


<-----Original Message-----> 
>From: justin bem [justin_...@yahoo.fr]
>Sent: 9/8/2009 9:06:23 AM
>To: helter...@care2.com
>Cc: r-h...@stat.math.ethz.ch
>Subject: Re: Re : [R] calling combinations of variable names
>
>may be this can work 
>
>testfun<-function(x) {
> rval=""
> k<-length(x)
> for (i in 1: k) rval<-paste(rval,x[i],sep="-")
> rval
>}
>
>v1<-paste("evalr",1:4,sep="")
>eval<-expand.grid(w=v1,x=v1,y=v1,z=v1)
>n<-dim(eval)[1]
>
>results<-rep("", n)
>
>for (i in 1:n) {
> row<-unique(unlist(eval[i,]))
>
> if (length(row)>=3) results[i]<-testfun(row)
>}
>
>You just have to replace testfun by your own function in this case ICC.
>
>Sincerly...
>
> 
>Justin BEM
>BP 1917 Yaoundé
>Tél (237) 76043774
>
>
>
>
>
>
>De : Helter Two <helter...@care2.com>
>À : r-help@r-project.org
>Envoyé le : Lundi, 7 Septembre 2009, 18h17mn 22s
>Objet : [R] calling combinations of variable names
>
>R-2.9.1, Windows7
>
>Dear list,
>
>I have a question to you that seems very simple to me, but I just can't
>figure it out.
>I have a dataframe called "ratings" which contains the following
>variables: evalR1, evalR2, evalR3, evalR4, scoreR1, scoreR2, scoreR3,
>scoreR4, opinionR1, opinionR2, opinionR3, opinionR4. (there are more
>variables, but this gives an idea of the data structure). 
>
>What I want is run several analyses on all 3 or 4-combinations of a
>given variable. So, for example, I want to compute the following ICC's
>(function from the psych package):
>ICC(cbind(evalR1,evalR2, evalR3))
>ICC(cbind(evalR1,evalR2, evalR4))
>ICC(cbind(evalR1, evalR3, evalR4))
>ICC(cbind(evalR2, evalR3, evalR4))
>ICC(cbind(evalR1, evalR2, evalR3, eval4)).
>
>I create a matrix containing the 3-combinations by combn(4,3). Now I
>need to call the variables into the function. 
>First, I tried paste as follows:
>combis <- combn(4,3) # this gives the 3-combinations
>attach(ratings)
>eval <-
>paste("evalR",combis[1,1],",evalR",combis[2,1],",evalR","combis[3,1],se
p
>="")
>(this is of course just for 1 combination, as an example)
>the output of this is "evalR1,"evalR2,evalR3", but when I run
>ICC(cbind(eval)), an error message is given which is not given when I
>enter ICC(cbind(evalR1,evalR2, evalR3)) manually. The function appears
>not to recognize the variable names. It also does not work to type
>ICC(cbind(unquote(eval))).
>Alternatively, I have tried the cat function, but also here ICC does
not
>recognize the input as variable names. 
>
>What am I doing wrong? How can I automatically construct the set of
>variable names such that a function recognizes them as variable names?
>ICC is one example, but there are also other computations to be run and
>the set of variables is pretty large, so typing the combinations of
>variable names manually is really unattractive.
>
>What am I missing? It seems to me that there probably is a very simple
>solution in R, but which?
>
>Thank you,
>Peter Verbeet
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help@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. 

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to