s-news
[Top] [All Lists]

Re:

To: "Nick Ellis" <Nick.Ellis@marine.csiro.au>, <s-news@wubios.wustl.edu>
Subject: Re:
From: "Abd Rahman Kassim" <rahmank@frim.gov.my>
Date: Fri, 27 Jul 2001 09:25:25 -0700
References: <NDBBIALDKDHAKHMNKPCOGEBGMNAA.Nick Ellis@marine.csiro.au>
Dear S-Plus User,
 
Many thanks to Dr. Nick Elis for the solution to my question on "ifelse". The solution is given below.
 
 
Abd Rahman Kassim
----- Original Message -----
From: Nick Ellis
Sent: Thursday, July 26, 2001 5:44 PM
Subject: RE: [S]

Try

all$group <- ifelse(as.numeric(as.character(all$kod)) < 1404, "D", "ND")

If it's a factor that has levels "10", "2", "7" then coercing it to numeric simply makes it 1, 2, 3, because that's how factors are coded. You need to convert to character first then convert those characters into numbers.

Nick Ellis
CSIRO Marine Research   mailto:Nick.Ellis@marine.csiro.au
PO Box 120              ph    +61 (07) 3826 7260
Cleveland QLD 4163      fax   +61 (07) 3826 7222
Australia               http://www.marine.csiro.au
 

-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu]On Behalf Of Abd Rahman Kassim
Sent: Saturday, July 28, 2001 1:20 AM
To: s-news@wubios.wustl.edu
Subject: [S]

Dear S-Plus Users,
 
Hi! I am trying to use the "ifelse" command to create a new variable "group". However I received an error message below. It seemed that the variable kod is read as "factors". So I've change the "data type" for kod from "factors" to "double" using the window menu. But the kod value change to new numbers altogether. Can any one advised me to solve this problem.
 

all$group <- ifelse(all$kod < 1404, "D", "ND")

Error in Ops.factor(all$kod, 1404): "<" not meaningful for factors

Thanks
 
Abd. Rahman Kassim

 

 

<Prev in Thread] Current Thread [Next in Thread>
  • Re:, Abd Rahman Kassim <=