Re: [R] weight

From: Natalie O'Toole <notoole_at_mtroyal.ca>
Date: Mon, 30 Apr 2007 10:38:39 -0600


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 ...

> 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_at_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_at_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_at_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]]



R-help_at_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 Mon 30 Apr 2007 - 21:15:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 30 Apr 2007 - 22:31:15 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.