s-news
[Top] [All Lists]

Re: Creating more than two level factor variables

To: Carlos Davidson <cdavidson@csus.edu>
Subject: Re: Creating more than two level factor variables
From: Chuck Cleland <ccleland@optonline.net>
Date: Tue, 31 Aug 2004 18:58:20 -0400
Cc: s-news@wubios.wustl.edu
In-reply-to: <5.2.0.9.0.20040831153447.011b3f88@pop3.saclink.csus.edu>
References: <5.2.0.9.0.20040831153447.011b3f88@pop3.saclink.csus.edu>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a3) Gecko/20040817
How about something like this?

fish <- as.factor(rep(c("Yes", "No"), 20))
depth <- as.factor(rep(c("Deep", "Shallow"), c(10,10)))

newfact <- as.factor(paste(as.character(fish), as.character(depth), sep=""))

Hope it helps.

Carlos Davidson wrote:
I would like to create a four level factor variable from two binary factor variables. So for a dataset with 1000 plus sites I have information on two different categorical binary variables (fish present - yes/no, and lake depth deep/shallow) and I would like to create a single factor variable with the factors "fishshallow","fishdeep", "nofishdeep","nofishshallow". Any suggestions of code to do this - call my two binary variales fish ( values "Y" and "N") and depth (values "Deep","Shallow")?

--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894

<Prev in Thread] Current Thread [Next in Thread>