Re: [R] weight
__ Hi, These are the variables in my file. I think the variable i'm having problems with is WTPP which is of the Factor type. Does anyone know how to fix this, please? Thanks, Nat data.frame': 290 obs. of 5 variables: $ PROV : num 48 48 48 48 48 48 48 48 48 48 ... $ REGION: num 4 4 4 4 4 4 4 4 4 4 ... $ GRADE : num 7 7 7 7 7 7 7 7 7 7 ... $ Y_Q10A: num 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 ... $ WTPP : Factor w/ 1884 levels "1,106.8250","1,336.5138",..: 1544 67 1568 40 221 1702 1702 1434 310 310 ... __ --- Douglas Bates <[EMAIL PROTECTED]> wrote: > On 4/28/07, John Kane <[EMAIL PROTECTED]> wrote: > > IIRC you have a yes/no smoking variable scored 1/2 > ? > > > > It is possibly being read in as a factor not as an > > integer. > > > > try > > class(df$smoking.variable) > > to see . > > Good point. In general I would recommend using > > str(df) > > to check on the class or storage type of all > variables in a data frame > if you are getting unexpected results when > manipulating it. That > function is carefully written to provide a maximum > of information in a > minimum of space. Yes but I'm an relative newbie at R and didn't realise that str() would do that. I always thought it was some kind of string function. Thanks, it makes life much easier. > > > > --- Natalie O'Toole <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > > I'm getting an error message: > > > > > > Error in df[, 1:4] * df[, 5] : non-numeric > argument > > > to binary operator > > > In addition: Warning message: > > > Incompatible methods ("Ops.data.frame", > > > "Ops.factor") for "*" > > > > > > here is my code: > > > > > > > > > ##reading in the file > > > happyguys<-read.table("c:/test4.dat", > header=TRUE, > > > row.names=1) > > > > > > ##subset the file based on Select If > > > > > > test<-subset(happyguys, PROV==48 & GRADE == 7 & > > > Y_Q10A < 9) > > > > > > ##sorting the file > > > > > > mydata<-test > > > mydataSorted<-mydata[ order(mydata$Y_Q10A), ] > > > print(mydataSorted) > > > > > > > > > ##assigning a different name to file > > > > > > happyguys<-mydataSorted > > > > > > > > > ##trying to weight my data > > > > > > data.frame<-happyguys > > > df<-data.frame > > > df1<-df[, 1:4] * df[, 5] > > > > > > ##getting error message here?? > > > > > > Error in df[, 1:4] * df[, 5] : non-numeric > argument > > > to binary operator > > > In addition: Warning message: > > > Incompatible methods ("Ops.data.frame", > > > "Ops.factor") for "*" > > > > > > Does anyone know what this error message means? > > > > > > I've been reviewing R code all day & getting > more > > > familiar with it > > > > > > Thanks, > > > > > > Nat > > > > > > > > > > > > > > > > > > > > This communication is intended for the use of > the > > > recipient to which it is > > > addressed, and may > > > contain confidential, personal, and or > privileged > > > information. Please > > > contact the sender > > > immediately if you are not the intended > recipient of > > > this communication, > > > and do not copy, > > > distribute, or take action relying on it. Any > > > communication received in > > > error, or subsequent > > > reply, should be deleted or destroyed. > > > [[alternative HTML version deleted]] > > > > > > __ > > > 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. > > > > > > > __ > > 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. > > > Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail at http://mrd.mail.yahoo.com/try_beta?.intl=ca This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, perso
Re: [R] weight
Hi, These are the variables in my file. I think the variable i'm having problems with is WTPP which is of the Factor type. Does anyone know how to fix this, please? Thanks, Nat data.frame': 290 obs. of 5 variables: $ PROV : num 48 48 48 48 48 48 48 48 48 48 ... $ REGION: num 4 4 4 4 4 4 4 4 4 4 ... $ GRADE : num 7 7 7 7 7 7 7 7 7 7 ... $ Y_Q10A: num 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 ... $ WTPP : Factor w/ 1884 levels "1,106.8250","1,336.5138",..: 1544 67 1568 40 221 1702 1702 1434 310 310 ... __ --- Douglas Bates <[EMAIL PROTECTED]> wrote: > On 4/28/07, John Kane <[EMAIL PROTECTED]> wrote: > > IIRC you have a yes/no smoking variable scored 1/2 > ? > > > > It is possibly being read in as a factor not as an > > integer. > > > > try > > class(df$smoking.variable) > > to see . > > Good point. In general I would recommend using > > str(df) > > to check on the class or storage type of all > variables in a data frame > if you are getting unexpected results when > manipulating it. That > function is carefully written to provide a maximum > of information in a > minimum of space. Yes but I'm an relative newbie at R and didn't realise that str() would do that. I always thought it was some kind of string function. Thanks, it makes life much easier. > > > > --- Natalie O'Toole <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > > I'm getting an error message: > > > > > > Error in df[, 1:4] * df[, 5] : non-numeric > argument > > > to binary operator > > > In addition: Warning message: > > > Incompatible methods ("Ops.data.frame", > > > "Ops.factor") for "*" > > > > > > here is my code: > > > > > > > > > ##reading in the file > > > happyguys<-read.table("c:/test4.dat", > header=TRUE, > > > row.names=1) > > > > > > ##subset the file based on Select If > > > > > > test<-subset(happyguys, PROV==48 & GRADE == 7 & > > > Y_Q10A < 9) > > > > > > ##sorting the file > > > > > > mydata<-test > > > mydataSorted<-mydata[ order(mydata$Y_Q10A), ] > > > print(mydataSorted) > > > > > > > > > ##assigning a different name to file > > > > > > happyguys<-mydataSorted > > > > > > > > > ##trying to weight my data > > > > > > data.frame<-happyguys > > > df<-data.frame > > > df1<-df[, 1:4] * df[, 5] > > > > > > ##getting error message here?? > > > > > > Error in df[, 1:4] * df[, 5] : non-numeric > argument > > > to binary operator > > > In addition: Warning message: > > > Incompatible methods ("Ops.data.frame", > > > "Ops.factor") for "*" > > > > > > Does anyone know what this error message means? > > > > > > I've been reviewing R code all day & getting > more > > > familiar with it > > > > > > Thanks, > > > > > > Nat > > > > > > > > > > > > > > > > > > > > This communication is intended for the use of > the > > > recipient to which it is > > > addressed, and may > > > contain confidential, personal, and or > privileged > > > information. Please > > > contact the sender > > > immediately if you are not the intended > recipient of > > > this communication, > > > and do not copy, > > > distribute, or take action relying on it. Any > > > communication received in > > > error, or subsequent > > > reply, should be deleted or destroyed. > > > [[alternative HTML version deleted]] > > > > > > __ > > > 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. > > > > > > > __ > > 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. > > > Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail at http://mrd.mail.yahoo.com/try_beta?.intl=ca This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. [[alternative HTML version deleted]] __ 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, min
Re: [R] weight
--- Douglas Bates <[EMAIL PROTECTED]> wrote: > On 4/28/07, John Kane <[EMAIL PROTECTED]> wrote: > > IIRC you have a yes/no smoking variable scored 1/2 > ? > > > > It is possibly being read in as a factor not as an > > integer. > > > > try > > class(df$smoking.variable) > > to see . > > Good point. In general I would recommend using > > str(df) > > to check on the class or storage type of all > variables in a data frame > if you are getting unexpected results when > manipulating it. That > function is carefully written to provide a maximum > of information in a > minimum of space. Yes but I'm an relative newbie at R and didn't realise that str() would do that. I always thought it was some kind of string function. Thanks, it makes life much easier. > > > > --- Natalie O'Toole <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > > I'm getting an error message: > > > > > > Error in df[, 1:4] * df[, 5] : non-numeric > argument > > > to binary operator > > > In addition: Warning message: > > > Incompatible methods ("Ops.data.frame", > > > "Ops.factor") for "*" > > > > > > here is my code: > > > > > > > > > ##reading in the file > > > happyguys<-read.table("c:/test4.dat", > header=TRUE, > > > row.names=1) > > > > > > ##subset the file based on Select If > > > > > > test<-subset(happyguys, PROV==48 & GRADE == 7 & > > > Y_Q10A < 9) > > > > > > ##sorting the file > > > > > > mydata<-test > > > mydataSorted<-mydata[ order(mydata$Y_Q10A), ] > > > print(mydataSorted) > > > > > > > > > ##assigning a different name to file > > > > > > happyguys<-mydataSorted > > > > > > > > > ##trying to weight my data > > > > > > data.frame<-happyguys > > > df<-data.frame > > > df1<-df[, 1:4] * df[, 5] > > > > > > ##getting error message here?? > > > > > > Error in df[, 1:4] * df[, 5] : non-numeric > argument > > > to binary operator > > > In addition: Warning message: > > > Incompatible methods ("Ops.data.frame", > > > "Ops.factor") for "*" > > > > > > Does anyone know what this error message means? > > > > > > I've been reviewing R code all day & getting > more > > > familiar with it > > > > > > Thanks, > > > > > > Nat > > > > > > > > > > > > > > > > > > > > This communication is intended for the use of > the > > > recipient to which it is > > > addressed, and may > > > contain confidential, personal, and or > privileged > > > information. Please > > > contact the sender > > > immediately if you are not the intended > recipient of > > > this communication, > > > and do not copy, > > > distribute, or take action relying on it. Any > > > communication received in > > > error, or subsequent > > > reply, should be deleted or destroyed. > > > [[alternative HTML version deleted]] > > > > > > __ > > > 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. > > > > > > > __ > > 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. > > > __ 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.
Re: [R] weight
On 4/28/07, John Kane <[EMAIL PROTECTED]> wrote: > IIRC you have a yes/no smoking variable scored 1/2 ? > > It is possibly being read in as a factor not as an > integer. > > try > class(df$smoking.variable) > to see . Good point. In general I would recommend using str(df) to check on the class or storage type of all variables in a data frame if you are getting unexpected results when manipulating it. That function is carefully written to provide a maximum of information in a minimum of space. > > > --- Natalie O'Toole <[EMAIL PROTECTED]> wrote: > > > Hi, > > > > I'm getting an error message: > > > > Error in df[, 1:4] * df[, 5] : non-numeric argument > > to binary operator > > In addition: Warning message: > > Incompatible methods ("Ops.data.frame", > > "Ops.factor") for "*" > > > > here is my code: > > > > > > ##reading in the file > > happyguys<-read.table("c:/test4.dat", header=TRUE, > > row.names=1) > > > > ##subset the file based on Select If > > > > test<-subset(happyguys, PROV==48 & GRADE == 7 & > > Y_Q10A < 9) > > > > ##sorting the file > > > > mydata<-test > > mydataSorted<-mydata[ order(mydata$Y_Q10A), ] > > print(mydataSorted) > > > > > > ##assigning a different name to file > > > > happyguys<-mydataSorted > > > > > > ##trying to weight my data > > > > data.frame<-happyguys > > df<-data.frame > > df1<-df[, 1:4] * df[, 5] > > > > ##getting error message here?? > > > > Error in df[, 1:4] * df[, 5] : non-numeric argument > > to binary operator > > In addition: Warning message: > > Incompatible methods ("Ops.data.frame", > > "Ops.factor") for "*" > > > > Does anyone know what this error message means? > > > > I've been reviewing R code all day & getting more > > familiar with it > > > > Thanks, > > > > Nat > > > > > > > > > > > > This communication is intended for the use of the > > recipient to which it is > > addressed, and may > > contain confidential, personal, and or privileged > > information. Please > > contact the sender > > immediately if you are not the intended recipient of > > this communication, > > and do not copy, > > distribute, or take action relying on it. Any > > communication received in > > error, or subsequent > > reply, should be deleted or destroyed. > > [[alternative HTML version deleted]] > > > > __ > > 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. > > > > __ > 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. > __ 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.
Re: [R] weight
IIRC you have a yes/no smoking variable scored 1/2 ? It is possibly being read in as a factor not as an integer. try class(df$smoking.variable) to see . --- Natalie O'Toole <[EMAIL PROTECTED]> wrote: > Hi, > > I'm getting an error message: > > Error in df[, 1:4] * df[, 5] : non-numeric argument > to binary operator > In addition: Warning message: > Incompatible methods ("Ops.data.frame", > "Ops.factor") for "*" > > here is my code: > > > ##reading in the file > happyguys<-read.table("c:/test4.dat", header=TRUE, > row.names=1) > > ##subset the file based on Select If > > test<-subset(happyguys, PROV==48 & GRADE == 7 & > Y_Q10A < 9) > > ##sorting the file > > mydata<-test > mydataSorted<-mydata[ order(mydata$Y_Q10A), ] > print(mydataSorted) > > > ##assigning a different name to file > > happyguys<-mydataSorted > > > ##trying to weight my data > > data.frame<-happyguys > df<-data.frame > df1<-df[, 1:4] * df[, 5] > > ##getting error message here?? > > Error in df[, 1:4] * df[, 5] : non-numeric argument > to binary operator > In addition: Warning message: > Incompatible methods ("Ops.data.frame", > "Ops.factor") for "*" > > Does anyone know what this error message means? > > I've been reviewing R code all day & getting more > familiar with it > > Thanks, > > Nat > > > > > This communication is intended for the use of the > recipient to which it is > addressed, and may > contain confidential, personal, and or privileged > information. Please > contact the sender > immediately if you are not the intended recipient of > this communication, > and do not copy, > distribute, or take action relying on it. Any > communication received in > error, or subsequent > reply, should be deleted or destroyed. > [[alternative HTML version deleted]] > > __ > 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. > __ 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.
Re: [R] weight
Hi, I'm getting an error message: Error in df[, 1:4] * df[, 5] : non-numeric argument to binary operator In addition: Warning message: Incompatible methods ("Ops.data.frame", "Ops.factor") for "*" here is my code: ##reading in the file happyguys<-read.table("c:/test4.dat", header=TRUE, row.names=1) ##subset the file based on Select If test<-subset(happyguys, PROV==48 & GRADE == 7 & Y_Q10A < 9) ##sorting the file mydata<-test mydataSorted<-mydata[ order(mydata$Y_Q10A), ] print(mydataSorted) ##assigning a different name to file happyguys<-mydataSorted ##trying to weight my data data.frame<-happyguys df<-data.frame df1<-df[, 1:4] * df[, 5] ##getting error message here?? Error in df[, 1:4] * df[, 5] : non-numeric argument to binary operator In addition: Warning message: Incompatible methods ("Ops.data.frame", "Ops.factor") for "*" Does anyone know what this error message means? I've been reviewing R code all day & getting more familiar with it Thanks, Nat This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. [[alternative HTML version deleted]] __ 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.
Re: [R] weight
Natalie O'Toole napsal(a): > Does anyone know why it is giving me this error? Any help would be greatly > appreciated!! > > Thanks, > > Nat > > > > myfile<-("c:/test2.txt") > mysubset<-myfile > mysubset$Y_Q02 <-mysubset$DVSELF <-NULL > mysubset2<-mysubset > mysubset2$Y_Q10B <-mysubset2$GP2_07 <-NULL > > myVariableNames<-c("PUMFID=rnorm(10)","PROV=rnorm(10)","REGION=rnorm(10)","GRADE=rnorm(10)","Y_Q10A=rnorm(10)","WTPP=rnorm(10)") >> df<-mysubset2[, 2:5] * mysubset2[, 6] HERE it has to stop with the error message you provided, not below. The code might run for a few more lines, but the problem is here. Your mysubset2, btw. we have no idea what that might be, aparently does not have 2 dimensions. Besides, your code is very dirty and it is indeed very easy to make a mistake in such code. You really should start reading some introductory manual as someone suggested before. You are not likely to recieve more (different) answers to questions of this kind. Petr > myVariableWidths<-c(5,2,1,2,1,12.4) > df<-read.fwf( > file=myfile, > width=myVariableWidths, > col.names=myVariableNames, > row.names="PUMFID", > fill=TRUE, > strip.white=TRUE) > > happyguys<-subset(df, PROV==48 & GRADE == 7 & Y_Q10A < 9) > print(happyguys) > > > where it is bolded, i'm getting the following error: Error in mysubset2[, > 2:5] : incorrect number of dimensions -- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic __ 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.
Re: [R] weight
Does anyone know why it is giving me this error? Any help would be greatly appreciated!! Thanks, Nat myfile<-("c:/test2.txt") mysubset<-myfile mysubset$Y_Q02 <-mysubset$DVSELF <-NULL mysubset2<-mysubset mysubset2$Y_Q10B <-mysubset2$GP2_07 <-NULL myVariableNames<-c("PUMFID=rnorm(10)","PROV=rnorm(10)","REGION=rnorm(10)","GRADE=rnorm(10)","Y_Q10A=rnorm(10)","WTPP=rnorm(10)") > df<-mysubset2[, 2:5] * mysubset2[, 6] myVariableWidths<-c(5,2,1,2,1,12.4) df<-read.fwf( file=myfile, width=myVariableWidths, col.names=myVariableNames, row.names="PUMFID", fill=TRUE, strip.white=TRUE) happyguys<-subset(df, PROV==48 & GRADE == 7 & Y_Q10A < 9) print(happyguys) where it is bolded, i'm getting the following error: Error in mysubset2[, 2:5] : incorrect number of dimensions __ __ Hi Dr. Kubovy, Here is my code so far: My question is: how do I then get a frequency count of Y_Q10A with the WTPP applied to it? myfile<-("c:/test2.txt") mysubset<-myfile mysubset$Y_Q02 <-mysubset$DVSELF <-NULL mysubset2<-mysubset mysubset2$Y_Q10B <-mysubset2$GP2_07 <-NULL myVariableNames<-c("PUMFID","PROV","REGION","GRADE","Y_Q10A","WTPP") myVariableWidths<-c(5,2,1,2,1,12.4) mysubset2<-read.fwf( file=myfile, width=myVariableWidths, col.names=myVariableNames, row.names="PUMFID", fill=TRUE, strip.white=TRUE) print(mysubset2) happyguys<-subset(mysubset2, PROV==48 & GRADE == 7 & Y_Q10A < 9) print(happyguys) df <- data.frame(PROV = rnorm(10), REGION = rnorm(10), GRADE = rnorm (10), Y_Q10A = rnorm(10), WTTP = rnorm(10)) df1 <- df[, 1:4] * df[, 5] Thanks, Nat __ df <- data.frame(PROV = rnorm(10), REGION = rnorm(10), GRADE = rnorm (10), Y_Q10A = rnorm(10), WTTP = rnorm(10)) df1 <- df[, 1:4] * df[, 5] The column you were worried about is not part of the data. You can get a vector of the record ids by rownames(df) On Apr 27, 2007, at 1:05 PM, Natalie O'Toole wrote: > I have the file below called happyguys. It is a subset of data. How > do I > apply the weight variable (WTPP) to this file? Can i just multiply > each > column (except the first column because it is a record id) by WTPP? > If the > answer is yes, how do I multiply one variable name by another? > > PROV REGION GRADE Y_Q10A WTPP > 83 48 4 7 2 342233324020 > 115 48 4 7 1 434413433040 > 185 48 4 7 1 432312433040 > 222 48 4 7 2 13311030 > 242 48 4 7 1 421313332020 > 247 48 4 7 2 312134212030 _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. [[alternative HTML version deleted]] __ 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. This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailm
Re: [R] weight
__ Hi Dr. Kubovy, Here is my code so far: My question is: how do I then get a frequency count of Y_Q10A with the WTPP applied to it? myfile<-("c:/test2.txt") mysubset<-myfile mysubset$Y_Q02 <-mysubset$DVSELF <-NULL mysubset2<-mysubset mysubset2$Y_Q10B <-mysubset2$GP2_07 <-NULL myVariableNames<-c("PUMFID","PROV","REGION","GRADE","Y_Q10A","WTPP") myVariableWidths<-c(5,2,1,2,1,12.4) mysubset2<-read.fwf( file=myfile, width=myVariableWidths, col.names=myVariableNames, row.names="PUMFID", fill=TRUE, strip.white=TRUE) print(mysubset2) happyguys<-subset(mysubset2, PROV==48 & GRADE == 7 & Y_Q10A < 9) print(happyguys) df <- data.frame(PROV = rnorm(10), REGION = rnorm(10), GRADE = rnorm (10), Y_Q10A = rnorm(10), WTTP = rnorm(10)) df1 <- df[, 1:4] * df[, 5] Thanks, Nat __ df <- data.frame(PROV = rnorm(10), REGION = rnorm(10), GRADE = rnorm (10), Y_Q10A = rnorm(10), WTTP = rnorm(10)) df1 <- df[, 1:4] * df[, 5] The column you were worried about is not part of the data. You can get a vector of the record ids by rownames(df) On Apr 27, 2007, at 1:05 PM, Natalie O'Toole wrote: > I have the file below called happyguys. It is a subset of data. How > do I > apply the weight variable (WTPP) to this file? Can i just multiply > each > column (except the first column because it is a record id) by WTPP? > If the > answer is yes, how do I multiply one variable name by another? > > PROV REGION GRADE Y_Q10A WTPP > 83 48 4 7 2 342233324020 > 115 48 4 7 1 434413433040 > 185 48 4 7 1 432312433040 > 222 48 4 7 2 13311030 > 242 48 4 7 1 421313332020 > 247 48 4 7 2 312134212030 _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. [[alternative HTML version deleted]] __ 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.
[R] weight
Hi, I have the file below called happyguys. It is a subset of data. How do I apply the weight variable (WTPP) to this file? Can i just multiply each column (except the first column because it is a record id) by WTPP? If the answer is yes, how do I multiply one variable name by another? Thanks, Nat PROV REGION GRADE Y_Q10A WTPP 83 48 4 7 2 342233324020 115 48 4 7 1 434413433040 185 48 4 7 1 432312433040 222 48 4 7 2 13311030 242 48 4 7 1 421313332020 247 48 4 7 2 312134212030 352 48 4 7 1 331112411040 562 48 4 7 2 331112321030 591 48 4 7 1 321334413030 663 48 4 7 2 441412442040 691 48 4 7 1 333213343020 730 48 4 7 1 43321030 850 48 4 7 1 343113422040 101648 4 7 1 322124413050 104148 4 7 1 331133432040 116348 4 7 1 433913439040 121148 4 7 2 211213421030 124548 4 7 2 231113331020 128348 4 7 1 432114432030 172348 4 7 2 233112422040 176548 4 7 1 331113421040 176648 4 7 2 443434234040 189448 4 7 2 311142321040 197648 4 7 1 113124312040 209248 4 7 1 333122343040 209348 4 7 1 341312412040 224848 4 7 2 31213040 239648 4 7 2 424113332040 240548 4 7 1 43220030 243848 4 7 1 421314432030 248848 4 7 1 421123322040 257948 4 7 2 312113241040 263748 4 7 1 421132432030 269948 4 7 1 444212433050 273848 4 7 1 24311040 275948 4 7 1 43311040 285648 4 7 1 14410060 296448 4 7 2 413223413030 310748 4 7 2 232233324030 316648 4 7 2 322234324030 316948 4 7 2 32424040 348048 4 7 2 311122421040 351948 4 7 2 432224234020 364548 4 7 1 321112221040 368148 4 7 2 344112432040 369848 4 7 1 44311030 370348 4 7 1 313311412040 373748 4 7 2 343234324040 388948 4 7 1 431123322020 389648 4 7 2 233313223030 391548 4 7 1 311312411040 392948 4 7 2 243314223030 393448 4 7 2 223112332040 393748 4 7 2 332122423030 395748 4 7 2 211194449030 398348 4 7 1 331312432040 405248 4 7 2 423313413040 414748 4 7 1 33321030 416848 4 7 2 322131323040 425348 4 7 1 343432324040 426348 4 7 1 211132411060 432448 4 7 1 331113421040 440248 4 7 2 321112331030 452848 4 7 1 444113312030 457048 4 7 2 441114221040 460048 4 7 1 22220030 464048 4 7 2 321234323050 467248 4 7 2 342134433040 470148 4 7 2 241433423020 471048 4 7 2 331114331030 472848 4 7 2 321213422050 476448 4 7 2 333413233040 476548 4 7 2 24224030 479448 4 7 2 32320030 491548 4 7 1 43420050 492148 4 7 2 443412413040 494448 4 7 1 411343412050 496348 4 7 2 322314313030 508948 4 7 1 22411040 517348 4 7 2 311134431030 546648 4 7 2 332332424030 548448 4 7 2 33324030 __ This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and or privileged information. Please contact the sender immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed. [[alternative HTML version deleted]] __ 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.
Re: [R] weight factor in somers2 function
[EMAIL PROTECTED] wrote: > Hi! > I’m trying to calculate de C index (concordance probability) through the > somers2 function (library Hmisc). I’m interesting on including the > sampling effort as a weight factor for the evaluation of model predictions > with real data. I’ve some questions about that: first of all I’m not > really sure if I can include sampling effort as a weight factor. Since the > weight factor should be a numeric vector of observation (usually > frequencies), I would expect that sampling effort could be a surrogate of > the frequency count of the number of subjects (i.e. frequency of > observation). However, when I use sampling effort as a weight factor, I > get C index larger than one. I guess/know this is statistically wrong. > Then, if these values were frequency of observation; what is working > incorrectly? What should be the characteristics of the weight vector? Or > what could be exactly included as weight factor? > Thank you very much! Send me the smallest artificial example you can construct and I'll work on it. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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.
[R] weight factor in somers2 function
Hi! Im trying to calculate de C index (concordance probability) through the somers2 function (library Hmisc). Im interesting on including the sampling effort as a weight factor for the evaluation of model predictions with real data. Ive some questions about that: first of all Im not really sure if I can include sampling effort as a weight factor. Since the weight factor should be a numeric vector of observation (usually frequencies), I would expect that sampling effort could be a surrogate of the frequency count of the number of subjects (i.e. frequency of observation). However, when I use sampling effort as a weight factor, I get C index larger than one. I guess/know this is statistically wrong. Then, if these values were frequency of observation; what is working incorrectly? What should be the characteristics of the weight vector? Or what could be exactly included as weight factor? Thank you very much! __ 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.
Re: [R] Weight and see
On Mon, 4 Dec 2006, Jean-Baptiste Combes wrote: > Hello, > > I am new on this list so please forgive me if I ask thnigs that were already > solved. > I am a french statistician and i would like to use R in my job, but I would > like to know (I haven't found yet) if R can take into account weights. I am > working on a study which had to get a weight variable, in order to make the > sample close to the population in terms of sex and universities (I am > working on students). > The 'survey' package can use weights and other sampling information to get correct population estimates. -thomas Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ 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.
[R] Weight and see
Hello, I am new on this list so please forgive me if I ask thnigs that were already solved. I am a french statistician and i would like to use R in my job, but I would like to know (I haven't found yet) if R can take into account weights. I am working on a study which had to get a weight variable, in order to make the sample close to the population in terms of sex and universities (I am working on students). Tahnks very much I expect that I have been clear enough, if not, please ask me some more explanations because I really want to use R. jb [[alternative HTML version deleted]] __ 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.
Re: [R] weight cases?
On Saturday 14 October 2006 16:52, Gabor Grothendieck wrote: > Try this (and round the result to make to it comparable to your > calculation): > > xtabs(weight ~ var1 + var2, my.data) Oh yes... :) It was so simple. Thanks for the cov.wt() as well. Regards, 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.
Re: [R] weight cases?
I missed your second question. See ?cov.wt On 10/14/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Try this (and round the result to make to it comparable to your calculation): > > xtabs(weight ~ var1 + var2, my.data) > > On 10/14/06, Adrian Dusa <[EMAIL PROTECTED]> wrote: > > Thanks for this Gabor, > > > > Sometimes weights can take various values, like 0.9 > > > rep(letters[1:3], c(1, 0.9, 1.6)) > > [1] "a" "c" > > > > What if the weight variable would be: > > > > my.data$weight <- c(0.4, 2, 1.3, 0.9, 1) > > > > The way I found the solution was to compute the unweighted table, then find > > the weight for each unique combination and multiply that with the > > corresponding row-column entry in the table. The solution though is not very > > satisfactory: > > > > my.data$var1 <- as.factor(my.data$var1) > > my.data$var2 <- as.factor(my.data$var2) > > total <- expand.grid(levels(my.data$var1), levels(my.data$var2)) > > rowsmy.data <- apply(unique(my.data[,1:2]), 1, paste, collapse="") > > rowstotal <- apply(total, 1, paste, collapse="") > > total$weight <- 0 > > total$weight[sapply(rowsmy.data, function(x) which(rowstotal == x))] <- > > unique(my.data)[,3] > > > > (unweighted <- table(my.data$var1, my.data$var2)) > > round(unweighted*total$weight, 0) > > > > > > Yet another question: how would the weight variable be applied to correlate > > two numerical variables? > > > > Best, > > Adrian > > > > On Saturday 14 October 2006 16:00, Gabor Grothendieck wrote: > > > Try this: > > > > > > table(lapply(my.data, rep, my.data$weight)[1:2]) > > > > > > On 10/14/06, Adrian Dusa <[EMAIL PROTECTED]> wrote: > > > > 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. > > > > -- > > 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.
Re: [R] weight cases?
Try this (and round the result to make to it comparable to your calculation): xtabs(weight ~ var1 + var2, my.data) On 10/14/06, Adrian Dusa <[EMAIL PROTECTED]> wrote: > Thanks for this Gabor, > > Sometimes weights can take various values, like 0.9 > > rep(letters[1:3], c(1, 0.9, 1.6)) > [1] "a" "c" > > What if the weight variable would be: > > my.data$weight <- c(0.4, 2, 1.3, 0.9, 1) > > The way I found the solution was to compute the unweighted table, then find > the weight for each unique combination and multiply that with the > corresponding row-column entry in the table. The solution though is not very > satisfactory: > > my.data$var1 <- as.factor(my.data$var1) > my.data$var2 <- as.factor(my.data$var2) > total <- expand.grid(levels(my.data$var1), levels(my.data$var2)) > rowsmy.data <- apply(unique(my.data[,1:2]), 1, paste, collapse="") > rowstotal <- apply(total, 1, paste, collapse="") > total$weight <- 0 > total$weight[sapply(rowsmy.data, function(x) which(rowstotal == x))] <- > unique(my.data)[,3] > > (unweighted <- table(my.data$var1, my.data$var2)) > round(unweighted*total$weight, 0) > > > Yet another question: how would the weight variable be applied to correlate > two numerical variables? > > Best, > Adrian > > On Saturday 14 October 2006 16:00, Gabor Grothendieck wrote: > > Try this: > > > > table(lapply(my.data, rep, my.data$weight)[1:2]) > > > > On 10/14/06, Adrian Dusa <[EMAIL PROTECTED]> wrote: > > > 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. > > -- > 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.
Re: [R] weight cases?
Thanks for this Gabor, Sometimes weights can take various values, like 0.9 > rep(letters[1:3], c(1, 0.9, 1.6)) [1] "a" "c" What if the weight variable would be: my.data$weight <- c(0.4, 2, 1.3, 0.9, 1) The way I found the solution was to compute the unweighted table, then find the weight for each unique combination and multiply that with the corresponding row-column entry in the table. The solution though is not very satisfactory: my.data$var1 <- as.factor(my.data$var1) my.data$var2 <- as.factor(my.data$var2) total <- expand.grid(levels(my.data$var1), levels(my.data$var2)) rowsmy.data <- apply(unique(my.data[,1:2]), 1, paste, collapse="") rowstotal <- apply(total, 1, paste, collapse="") total$weight <- 0 total$weight[sapply(rowsmy.data, function(x) which(rowstotal == x))] <- unique(my.data)[,3] (unweighted <- table(my.data$var1, my.data$var2)) round(unweighted*total$weight, 0) Yet another question: how would the weight variable be applied to correlate two numerical variables? Best, Adrian On Saturday 14 October 2006 16:00, Gabor Grothendieck wrote: > Try this: > > table(lapply(my.data, rep, my.data$weight)[1:2]) > > On 10/14/06, Adrian Dusa <[EMAIL PROTECTED]> wrote: > > 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. -- 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.
Re: [R] weight cases?
Try this: table(lapply(my.data, rep, my.data$weight)[1:2]) On 10/14/06, Adrian Dusa <[EMAIL PROTECTED]> wrote: > > 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. > __ 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.
[R] weight cases?
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.