s-news
[Top] [All Lists]

Re: Create new category column in dataframe

To: <s-news@lists.biostat.wustl.edu>
Subject: Re: Create new category column in dataframe
From: "Redfearn, Christian" <redfearn@sppd.usc.edu>
Date: Sat, 1 Nov 2008 12:02:42 -0700
In-reply-to: <549137.71949.qm@web76112.mail.sg1.yahoo.com>
References: <549137.71949.qm@web76112.mail.sg1.yahoo.com>
Thread-index: Ack8UHbRHwbagNKqRL+lzjcdfEOeNwAAwV0A
Thread-topic: [S] Create new category column in dataframe

Greetings,

 

I’m using a simple linear regression model with factors as regressors, and am uncertain about the interpretation.

 

Specifically, I have the following regression specified:

 

l <- lm(log(price) ~ log(sfla) + log(land.sf) + bed + fbath + recroom + as.factor(sf.type)

 

The results show coefficients for four of the five levels of the sf.type variable, but report them as “as.factor(sf.type)1” …”as.factor(sf.type)4”

 

My question is which one is omitted?  And, which of the five types is “1”, “2”, etc?  That is, how are the levels mapped and assigned? Is there a rule that would make this easy to read?

 

I could create the dummy variables by hand, but this seems clumsy.

 

Thanks,

 

Chris.

 

 

From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Lim Weiyang
Sent: Saturday, November 01, 2008 11:34 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Create new category column in dataframe

 

Dear S-Users,

 

I wonder whether I can create a new factor column with new categories and names derived from a column with numeric values. For example, I wish to have four categories of the following form and names(firstcat, secondcat, thirdcat, fourthcat):

 

Between -1 and 1: firstcat

Between -2 and -1 or between 1 and 2: secondcat

Between -5 and -2 or between 2 and 5: thirdcat

Below -5 or more than 5: fourthcat

 

I have looked at functions cut, factor etc but do not know how to use them for my purpose.

 

Sincerely hope to have some assistance.

 

Thank you.

 

Best Regards,

Weiyang

 

 

 


New Email names for you!
Get the Email name you've always wanted on the new @ymail and @rocketmail.
Hurry before someone else does!

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