[R] vector problem

Gabor Grothendieck ggrothendieck at gmail.com
Fri Nov 24 23:46:53 CET 2006


merge.zoo can do that:

> p1 <- 100
> p2 <-  c(20, 80)
> p3 <- c(40, 10, 50)
> library(zoo)
> t(merge(p1 = zoo(p1), p2 = zoo(p2), p3 = zoo(p3), fill = 0))
     1  2  3
p1 100  0  0
p2  20 80  0
p3  40 10 50

On 11/24/06, bunny , lautloscrew.com <bunny at lautloscrew.com> wrote:
> my vector of answers could have a length of  3 or only one. i want to
> rbind all the answers into one matrix. (one vector for each participant)
> answers vectors for one participant could look like:
>
> p1:   100
> p2:  20 80
> p3: 40 10 50
>
> i have the following loop which should rbind them but i get no proper
> matrix.
> i´d like to have something like this
>
> 100 0 0
> 20 80 0
> 40 10 50
>
> Here´s my loop:
>
>
> for(s in 1:length(fr))
>        {
>        ### ansmini is a complete survey of one participant
>                ansmini3=answers[relevant[s,],]
>
>        for(x in 1:length(qidsb3))
>                {
>                # outputs all answer ids out of all data which belong to the qids
> out of the question id vector
>                        ansmin3=ansmini3[,1][ansmini3[,3]==qidsb3[x]]
>                        newb3=rbind(newb3,ansmin3)
>                }
>        }
>
> this is doing the job for question with only one answer, so i have
> only one answer id.
> in this new case i have 1-3 possible answers.. that´s why i´am not
> getting a nice newb3 matrix...
>
> i´d really be happy about some advice!
> thanks in advance
>
> matthias



More information about the R-help mailing list