Thank you very much to all of you for the responses!
Phil, the following two examples worked well in re-categorizing. Is there
any way I can retain my original data.frame format? Once I re-categorize
the data, the format becomes numeric and the original column names are not
retained. I
On 2010-07-17 23:03, Peter Dalgaard wrote:
Ista Zahn wrote:
Hi,
On Fri, Jul 16, 2010 at 5:18 PM, CC turtysm...@gmail.com wrote:
I am sure this is a very basic question:
I have 600,000 categorical variables in a data.frame - each of which is
classified as 0, 1, or 2
What I would like to do is
Ista Zahn wrote:
Hi,
On Fri, Jul 16, 2010 at 5:18 PM, CC turtysm...@gmail.com wrote:
I am sure this is a very basic question:
I have 600,000 categorical variables in a data.frame - each of which is
classified as 0, 1, or 2
What I would like to do is collapse 1 and 2 and leave 0 by itself,
Please look at Peter Dalgaard's response a little more
carefully. There's a big difference between the levels=
argument (which must be unique) and the labels= argument
(which need not be). Here are two ways
to do what you want:
d = 0:2
factor(d,levels=0:2,labels=c('0','1','1'))
[1] 0 1 1
On Sat, Jul 17, 2010 at 9:03 PM, Peter Dalgaard pda...@gmail.com wrote:
Ista Zahn wrote:
Hi,
On Fri, Jul 16, 2010 at 5:18 PM, CC turtysm...@gmail.com wrote:
I am sure this is a very basic question:
I have 600,000 categorical variables in a data.frame - each of which is
classified as 0, 1,
I am sure this is a very basic question:
I have 600,000 categorical variables in a data.frame - each of which is
classified as 0, 1, or 2
What I would like to do is collapse 1 and 2 and leave 0 by itself,
such that after re-categorizing 0 = 0; 1 = 1 and 2 = 1 --- in
the end I only want 0 and 1
Do you want to replace specific values of a data set?
df - sample(c(0,1,2),600,replace=T)
table(df)
df[df==2]-1
table(df)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-collapse-categories-or-re-categorize-variables-tp2291704p2291727.html
Sent from
Hi:
See ? levels. Here's a toy example:
x - factor(sample(0:2, 10, replace = TRUE))
x
[1] 1 2 1 0 2 2 2 2 2 1
Levels: 0 1 2
levels(x) - c(0, 1, 1)# Change level 2 to 1
x
[1] 1 1 1 0 1 1 1 1 1 1
Levels: 0 1
HTH,
Dennis
On Fri, Jul 16, 2010 at 10:18 AM, CC turtysm...@gmail.com wrote:
Hi,
On Fri, Jul 16, 2010 at 5:18 PM, CC turtysm...@gmail.com wrote:
I am sure this is a very basic question:
I have 600,000 categorical variables in a data.frame - each of which is
classified as 0, 1, or 2
What I would like to do is collapse 1 and 2 and leave 0 by itself,
such that after
9 matches
Mail list logo