[R] weight cases?
Adrian Dusa
dusa.adrian at gmail.com
Sat Oct 14 14:58:08 CEST 2006
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
More information about the R-help
mailing list