# Re: [R] Sorting Data?

From: Martin Klaffenboeck (martin.klaffenboeck@gmx.at)
Date: Sat 29 May 2004 - 03:48:55 EST

```Message-id: <20040528174855.GC3509@martin.kleinerdrache.org>

```

Am 28.05.2004 15:18:58 schrieb(en) Jonathan Baron:

> >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 don't think this is a trivial problem at all, so I am hesitant
> to offer advice. I see now that you reall do want a matrix,
> where you have mothers in the columns and daughters in the rows,
> and distance (difference, similarity) measures in the cells.
> Perhaps you have several such measures, so you want a
> three-dimensional array.

Hm. I don't know. I tried the following:

Creating a new Variable by:

Fbg[['F.gesamt']] <- rowSums(Fbg[11:27], na.rm=TRUE)

Which contains everything from F01 to F17 as sum().

Than I do the thing to split mothers from daugthers as you told me.
The next step i get:

dist(Muetter['F.gesamt'] - Toechter['F.gesamt'])

Which gives me some output, where I am not sure what it is. ;-(

But it looks like the thing I want, but I think I don't really have the
right data inside.

> You might do something like this. First define a function to
>
> Itemdist <- function(x,y) {sum(abs(x[-(1:4)]-y[-(1:4)]))}
>
> Dists <- matrix(NA,nrow(Daughters),nrow(Mothers))
>
> for (i in 1:nrow(Daughters)
> {for (j in 1:nrow(Mothers))
> {Dists[i,j] <- Itemdist(Daughters[i,],Mothers[j,])}}

Hm. I get some syntax errors inside this. If you want you can have my
small sample I'm now createing a source file about. There I have 12
mother daugther pairs. I will get about 20 pairs within the next two
months, but then I will have my source file (loading by source("file.
R")) ready. The small sample is just to work now.