[R] weight cases?

From: Adrian Dusa <dusa.adrian_at_gmail.com>
Date: Sat 14 Oct 2006 - 12:58:08 GMT

Dear all,

This is probably a stupid question for which I have a solution, which unfortunately is not as straighforward as I'd like. I wonder if there's a simple way to apply a weighting variable for the cases of a dataframe (well I'm sure there is, I just cannot find it). My toy example:

> my.data <- data.frame(var1=c("c", "e", "a", "d", "b"),

                        var2=c("E", "B", "A", "C", "D"),
                        weight=c(1, 2, 1, 1, 1))

> table(my.data$var1, my.data$var2)

    A B C D E
  a 1 0 0 0 0
  b 0 0 0 1 0
  c 0 0 0 0 1
  d 0 0 1 0 0
  e 0 1 0 0 0

Applying the weight variable, the table should yield a value of 2 for the "eB" combination:

> table(my.data$var1, my.data$var2)

    A B C D E
  a 1 0 0 0 0
  b 0 0 0 1 0
  c 0 0 0 0 1
  d 0 0 1 0 0
  e 0 2 0 0 0

Thanks in advance,
Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

______________________________________________
R-help@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.
Received on Sat Oct 14 22:57:11 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 14 Oct 2006 - 13:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.