Re: [R] Collapse factor levels

2009-11-01 Thread Kevin E. Thorpe
Peter Dalgaard wrote: Kevin E. Thorpe wrote: I'm sure this is simple enough, but an R site search on my subject terms did suggest a solution. I have a numeric vector with many values that I wish to create a factor from having only a few levels. Here is a toy example. > x <- 1:10 > x <- fact

Re: [R] Collapse factor levels

2009-11-01 Thread Peter Dalgaard
Kevin E. Thorpe wrote: I'm sure this is simple enough, but an R site search on my subject terms did suggest a solution. I have a numeric vector with many values that I wish to create a factor from having only a few levels. Here is a toy example. > x <- 1:10 > x <- factor(x,levels=1:10,labels

Re: [R] Collapse factor levels

2009-11-01 Thread David Winsemius
On Nov 1, 2009, at 3:51 PM, Kevin E. Thorpe wrote: I'm sure this is simple enough, but an R site search on my subject terms did suggest a solution. I have a numeric vector with many values that I wish to create a factor from having only a few levels. Here is a toy example. > x <- 1:10 > x <-

Re: [R] Collapse factor levels

2009-11-01 Thread Jorge Ivan Velez
Hi Kevin, Here are two suggestions: # Combination of levels() and table() table(levels(x)) # A B C # 3 3 4 # Or defining a function mysummary <- function(x) table(levels(x)) # you can easily improve it :-) mysummary(x) # A B C # 3 3 4 HTH, Jorge On Sun, Nov 1, 2009 at 3:51 PM, Kevin E. Thorpe

[R] Collapse factor levels

2009-11-01 Thread Kevin E. Thorpe
I'm sure this is simple enough, but an R site search on my subject terms did suggest a solution. I have a numeric vector with many values that I wish to create a factor from having only a few levels. Here is a toy example. > x <- 1:10 > x <- factor(x,levels=1:10,labels=c("A","A","A","B","B","B"