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. Hm. How do I have to do now? Thanks, Martin
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. 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: Myfile$F4 <- -Myfile$F4 # reverse polarity Myfile$F7 <- -Myfile$F7 Mothers <- Myfile[Family="M",] Daughters <- Myfile[Family="D",] Itemdiffs <- Mothers[,-(1:4)]-Daughters[,-(1:4)] # the -(1:4) # removes cols 1:4 or Itemdiffs <- (Mothers-Daughters)[,-(1:4)] or Itemdiffs <- abs(Mothers[,-(1:4)]-Daughters[,-(1:4)]) or maybe Itemdiffs <- rowMeans(abs(Mothers[,-(1:4)]-Daughters[,-(1:4)])) and for the difference of the sums Sumdiffs <- rowMeans(Mothers[,-(1:4)]-Daughters[,-(1:4)]) If my assumptions are wrong, then more work is needed. You might have to sort by Code, e.g., Myfile <- Myfile[sort(Myfile$Code),] And you might have to match by Code, assuming each daughter has one mother but one mother can have 2 daughters. Here is a VERY CRUDE way (which may not work): Itemdiff <- matrix(NA,nrow(Daughter),NUMBER OF ITEMS) # fill this in for (i in 1:nrow(Daughter)) {Itemdiff[i,] <- Daughter[i,]-Mother[Mother$Code==Daughter[i,Code]} Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron R search page: http://finzi.psych.upenn.edu/
OK. Maybe 2 errors. I already found one: On 05/27/04 16:43, Jonathan Baron wrote:>Sumdiffs <- rowMeans(Mothers[,-(1:4)]-Daughters[,-(1:4)])should be Sumdiffs <- rowMeans(Mothers[,-(1:4)])-rowMeans(Daughters[,-(1:4)])
Am 27.05.2004 22:11:04 schrieb(en) Berton Gunter:> Your question does not make a lot of sense to me. If you only want > to compute distances between mothers and THEIR daughters, you > cannot have a matrix, because different mothers have different > numbers of daughters.Thats true, but we took only one mother and one daugther in our sample, so in this sample we have only on daugther from one mother.> Do you want to define the distance between a mother and someone > else's daughter as 0 or INF ? Do you want to show that mothers and > their daughters are more similar then mothers and someone else's > daughters?Thats my question, yes. ;-)> You either need to think about what you wish to do more carefully or > express it more carefully. At least for me. Maybe someone else will > understand you better.Sorry, its the first time for me to talking about statistics in english and so I have to learn to express it better. Martin> -- Bert > > 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. > > > > Hm. How do I have to do now? > > > > Thanks, > > Martin > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > -- > > Bert Gunter > > Non-Clinical Biostatistics > Genentech > MS: 240B > Phone: 650-467-7374 > > > "The business of the statistician is to catalyze the scientific > learning > process." > > -- George E.P. Box > > > > >
Am 27.05.2004 22:17:04 schrieb(en) Patrick Burns:> First comment: "F" is a bad name to use for an object as it > masks the commonly used meaning of FALSE.Oh, thanks, I just took F because 'Fragebogen' is such a long variable. But you are right, I will change that.> You'll probably get some better answers, but you can ensure > a standard order with: > > Fsort <- Fdf[order(Fdf[, 'Code'], Fdf[, 'Family']), ] > > And then perhaps use "reshape".I will look at this closer. Im now reshaping arround and don't know how I can then create a intercorrelation matrix or a (euklidic) distance matrix. But thanks, Martin> Patrick Burns > > Burns Statistics > 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") > > 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. >> >> Hm. How do I have to do now? >> >> Thanks, >> Martin >> >> ______________________________________________ >> R-help at stat.math.ethz.ch mailing list >> https://www.stat.math.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! >> http://www.R-project.org/posting-guide.html >> >> > > > > >