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 133112222030 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 431111321030 850 48 4 7 1 343113422040 1016 48 4 7 1 322124413050 1041 48 4 7 1 331133432040 1163 48 4 7 1 433913439040 1211 48 4 7 2 211213421030 1245 48 4 7 2 231113331020 1283 48 4 7 1 432114432030 1723 48 4 7 2 233112422040 1765 48 4 7 1 331113421040 1766 48 4 7 2 443434234040 1894 48 4 7 2 311142321040 1976 48 4 7 1 113124312040 2092 48 4 7 1 333122343040 2093 48 4 7 1 341312412040 2248 48 4 7 2 312333313040 2396 48 4 7 2 424113332040 2405 48 4 7 1 411113220030 2438 48 4 7 1 421314432030 2488 48 4 7 1 421123322040 2579 48 4 7 2 312113241040 2637 48 4 7 1 421132432030 2699 48 4 7 1 444212433050 2738 48 4 7 1 241111311040 2759 48 4 7 1 431111311040 2856 48 4 7 1 111114410060 2964 48 4 7 2 413223413030 3107 48 4 7 2 232233324030 3166 48 4 7 2 322234324030 3169 48 4 7 2 333332424040 3480 48 4 7 2 311122421040 3519 48 4 7 2 432224234020 3645 48 4 7 1 321112221040 3681 48 4 7 2 344112432040 3698 48 4 7 1 441111311030 3703 48 4 7 1 313311412040 3737 48 4 7 2 343234324040 3889 48 4 7 1 431123322020 3896 48 4 7 2 233313223030 3915 48 4 7 1 311312411040 3929 48 4 7 2 243314223030 3934 48 4 7 2 223112332040 3937 48 4 7 2 332122423030 3957 48 4 7 2 211194449030 3983 48 4 7 1 331312432040 4052 48 4 7 2 423313413040 4147 48 4 7 1 331111321030 4168 48 4 7 2 322131323040 4253 48 4 7 1 343432324040 4263 48 4 7 1 211132411060 4324 48 4 7 1 331113421040 4402 48 4 7 2 321112331030 4528 48 4 7 1 444113312030 4570 48 4 7 2 441114221040 4600 48 4 7 1 211112220030 4640 48 4 7 2 321234323050 4672 48 4 7 2 342134433040 4701 48 4 7 2 241433423020 4710 48 4 7 2 331114331030 4728 48 4 7 2 321213422050 4764 48 4 7 2 333413233040 4765 48 4 7 2 243333224030 4794 48 4 7 2 311112320030 4915 48 4 7 1 411113420050 4921 48 4 7 2 443412413040 4944 48 4 7 1 411343412050 4963 48 4 7 2 322314313030 5089 48 4 7 1 221111411040 5173 48 4 7 2 311134431030 5466 48 4 7 2 332332424030 5484 48 4 7 2 333333324030 __________________ ------------------------------------------------------------------------------------------------------------------------ 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]]
__________________ 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 133112222030 > 242 48 4 7 1 421313332020 > 247 48 4 7 2 312134212030<snip> _____________________________ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 Parcels: Room 102 Gilmer Hall McCormick Road Charlottesville, 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]]
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 133112222030 > 242 48 4 7 1 421313332020 > 247 48 4 7 2 312134212030<snip> _____________________________ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 Parcels: Room 102 Gilmer Hall McCormick Road Charlottesville, 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]]
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]]
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 <bates@stat.wisc.edu> wrote:> On 4/28/07, John Kane <jrkrideau@yahoo.ca> 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 <notoole@mtroyal.ca> 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]]
__________________ 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 <bates@stat.wisc.edu> wrote:> On 4/28/07, John Kane <jrkrideau@yahoo.ca> 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 <notoole@mtroyal.ca> 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, 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]]