[R] Sorting Data?

Martin Klaffenboeck martin.klaffenboeck at gmx.at
Fri May 28 12:21:42 CEST 2004

Am 27.05.2004 22:43:02 schrieb(en) Jonathan Baron:
> On 05/27/04 21:58, Martin Klaffenboeck wrote:
> >Hello,
> >
> >Im reading through some manuals, but I cannot find my answer.
> >
> >I have a file containing many data:
> >
> >Vpn	Code	Family	Age	F1	F2	...	F17
> >1	1	M	46	1	2	...	1
> >2	1	D	18	3	2	...	4
> >3	2	M	50	3	3	...	3
> >...
> >and so on.
> >
> >Now I can read it by:
> >
> >F = read.table("file", header=T)
> >
> >but now I want to seperate the mothers (M) and daugthers (D) of the
> >family with all the data in all other fields.  How can I do that?
> >
> >The 'Code' Tells me which mother belongs to which dougther.  I want
> to
> >make a matrix where I have the mothers on one and the daugthers on
> the
> >other axis and compair the distance of every question (F1...F17) and
> >the distance of the sum of this questions.  The questions are
> semantic
> >differencials, 5 values.  F4, and F7 must have reverse polarity in
> this
> >case.
> The following is not tested and probably contains at least one error.

Thanks, that helps me much as I am a R newbie.

> Lets assume that there is one mother per daughter and one
> daughter per mother, and your file is Myfile, and the Codes are
> in order.  One way is this:

Ok, we really have only one daughter per mother in our sample.
Im sorting by:

Myfile <- read.table("Fragebogen.data", header=TRUE)
Myfile <- Myfile[order(e[, 'Code'], Myfile[, 'Family']), ]

Code has one equal code for mother and daugther the same - so I know  
which mother has which daughter, Family tells me if the person it she  
mother or the daugther.

> Myfile$F4 <- -Myfile$F4 # reverse polarity
> Myfile$F7 <- -Myfile$F7

Is this also true, if we have a semantic differential with 5 steps? 
(from 1 to five.  I have one missing value (NA), should I set it to 0?) 
(please tell me also if I use incorrect words).
You didn't know that I assume.  So now I'm doing:

Myfile$F3 <- 5-Myfile$F3

that seems to be good for me, please tell me what you think.

> Mothers <- Myfile[Family="M",]
> Daughters <- Myfile[Family="D",]

Hm.  This seems not to work for me i was testing arround, for me seems  
to work:

Mothers <- Myfile[Myfile[["Family"]]=="M",]
Daugthers <- ...

I hope we have the same results now. ;-)  Im really a newbie in R.

> Itemdiffs <- Mothers[,-(1:4)]-Daughters[,-(1:4)] # the -(1:4)
>                                                  # removes cols 1:4

Ok, this seems to work, also but I don't really know what I am doing  
with it.  Also the other things.

I have to test the hypothesis:  Does a daugther answer the questions  
(semantic differential) more equal the own mother and more different to  
the mothers of the other daugthers.  I hope you get that in  
english. ;-)


More information about the R-help mailing list