On Tue, 9 Sep 2014 04:42:11 PM Norbert D?rrer wrote:> Dear Experts
>
> I'm quite new to the world of R; so maybe my question is kind of
> beginners...
>
> I am right now trying to analyse questionnaire data (CAWI) for
producing a> image/positioning map of the competitors of my company; when
programming> the CAWI, a split design was needed; every respondent had to
answer a> couple of multiple-choice questions (on reputation of company,
image,> sympathy etc.; 1 "perfect" to 5 "absolutely not
perfect") for two
companies> only - out of a list of several companies; companies were chosen
randomly.>
> So what I have now is two variables that tell me which two
companies the> respondent was actually evaluating...
> Company 1: A, B, C, D, E, F or G
> Company 2: A, B, C, D, E, F or G
>
> ... and of course several image-related variables:
> reputation of company 1: 3,4,2,3,5,1,2,3,4,2,3,1,5 and so on
> reputation of company 2: 5,2,3,4,2,5,1,2,3,2,4,21 and so on
> image of company 1: 2,4,3,5,2,3,4,1,2,5,3,4,2 and so on
> image of company 2: 3,4,5,2,5,4,5,3,4,2,5,1,2 and so on
> sympathy of company 1: 1,5,3,4,2,5,3,4,1,2,3,4,5 and so on
> sympathy of company 2: 5,5,4,5,3,3,4,3,3,3,4,2,5 and so on
> etc.
>
>
> But what I need in order to do proper calculations is one
> Reputation/Image/Sympathy-Variable for every single company, like
this:> reputation of Company A: e.g. 3,4,3,5,NA,3,NA,5,2,1,NA,NA
> reputation of Company B: e.g. NA,4,3,5,NA,3,NA,5,2,1,NA
> reputation of Company C and so on
> image of Company A:...
> image of Company B :...
> image of Company C and so on
> sympathy of Company A:...
> sympathy of Company B :...
> sympathy of Company C and so on
>
> So I need some syntax to compute a new variable e.g.
"reputation_CompanyA"> that contains the values of "reputation of company 1" whenever
"Company> 1"=A and that contains the values of "reputation of company
2"
whenever> "Company 2"=A... else is of course missing values!
>
> The solution has to has something to do with loops and flow control,
but I> really can't solve this puzzle.
>
Hi Norbert,
I'll assume that you have your data (call it nddf) in a form something
like this:
rep1 rep2 img1 img2 sym1 sym2 ...
S1 3 4 2 3 1 5
S2 4 2 4 4 5 5
S3 ...
and your allocation of companies to subjects (call it subcomp) is in
another file like this:
S1 A C
S2 B D
S3 ...
If so, you can do something like this. Say you surveyed 10 subjects
and your overall variable is the sum of the five (?) scores:
# create a list of company by attribute scores
comp_by_attr<-vector("list",7)
names(comp_by_attr)<-LETTERS[1:7]
# step through your rating data
for(subject in 1:10) {
company1<-
which(subcomp[subject,1]==names(company_by_attr))
company2<-
which(subcomp[subject,2]==names(company_by_attr))
# add the sum of the subject's company 1 ratings
comp_by_attr[[company1]]<-c(comp_by_attr[[company1]],
sum(nddf[subject,seq(1,9,by=2)]))
# add the sum of the subject's company 2 ratings
comp_by_attr[[company2]]<-c(comp_by_attr[[company2]],
sum(nddf[subject,seq(1,9,by=2)]))
}
You should now have a list of seven elements, each labeled with the
code of the company and containing the overall scores for that
company. Since I don't have the data, I haven't checked this, but it
may get you out of trouble.
Jim