[R] vector problem

bunny , lautloscrew.com bunny at lautloscrew.com
Sat Nov 25 20:26:42 CET 2006


thanks for your suggestions.
S Poetry looks really amazing, but also a lot of work for me.
I am pretty sure i´ll spent some hours over it.. (i should say weeks) :)

thanks for the zoo tips also..
but somehow i found out my  problems are elsewhere.

i have to work with the following survey.
people were able to answer
in percentages that have to sum up to 100.

and answer is saved in one line of the answers.txt which i read in.
one answer from one participant can therefore content 1-3 rows.
e.g.:
participant1 says 10 and 20 and 70 and has therefore 3 rows
participant2 says 80 and nothing and 20 and has unfortunately 2 rows

what  i wand to have is a matrix of all the answers with three  
columns where every participant is a row.
should look like this:
10 20 70
80 0 20

I know data could have been saved better... but i do have this ****  
dataset now and gotta rumble with it.

i will try again now, but i am still very glad about any help  
because, this is my first real data apart from the practice stuff !
thanks in advance



Am 25.11.2006 um 11:24 schrieb Patrick Burns:

> Not an answer to your specific question, but S Poetry
> may be of use to you.  In particular, it will say why it is
> not good practice to 'rbind' an object in a loop -- it is
> much better to create the matrix with its full size and then
> subscript into it.
>
> Patrick Burns
> patrick at burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
> bunny , lautloscrew.com wrote:
>
>> Hello out there,
>>
>> i am not yet that experienced and trying to my best on a real  
>> survey.  but i am stuck with a little matrix / vector problem.
>> 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
>>
>>
>>
>> 	[[alternative HTML version deleted]]
>>
>>
>> --------------------------------------------------------------------- 
>> ---
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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.
>>



More information about the R-help mailing list