Re: [R] binned column in a data.frame

2007-07-20 Thread Mike Meredith


Try something like this:

x - c(1,2,6,8,13,0,5,10, runif(10) * 100)
tmp - x %/% 5 + 1
bin.names - paste((0:19) * 5, (1:20) * 5, sep=-)
data.frame(Start = x, Binned_Start = bin.names[tmp])

This assumes you want (eg.) 5 in the 5-10 bin, not the 0-5 bin. You may also
want to make Binned_Start into a factor rather than a character vector.

HTH, Mike.



João Fadista wrote:
 
 Dear all,
  
 I would like to know how can I create a binned column in a data.frame. The
 output that I would like is something like this: 
  
 Start  Binned_Start
 10-5
 20-5
 65-10
 85-10
 13  10-15
 ...
  
  
  
 
 Best regards
 
 João Fadista
 Ph.d. student
 
 
   
UNIVERSITY OF AARHUS   
 Faculty of Agricultural Sciences  
 Dept. of Genetics and Biotechnology   
 Blichers Allé 20, P.O. BOX 50 
 DK-8830 Tjele 
   
 Phone: +45 8999 1900  
 Direct:+45 8999 1900  
 E-mail:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]   
 Web:   www.agrsci.org http://www.agrsci.org/
 
 
 News and news media http://www.agrsci.org/navigation/nyheder_og_presse .
 
 This email may contain information that is confidential. Any use or
 publication of this email without written permission from Faculty of
 Agricultural Sciences is not allowed. If you are not the intended
 recipient, please notify Faculty of Agricultural Sciences immediately and
 delete this email.
 
 
   [[alternative HTML version deleted]]
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/binned-column-in-a-data.frame-tf4115787.html#a11705240
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] binned column in a data.frame

2007-07-20 Thread jim holtman
You can also use 'cut' to break the bins:

 x - c(1,2,6,8,13,0,5,10, runif(10) * 100)
 x.bins - seq(0, max(x)+5, 5)
 x.cut - cut(x, breaks=x.bins, include.lowest=TRUE)
 x.names - paste(head(x.bins, -1), tail(x.bins, -1), sep='-')
 data.frame(x, bins=x.names[x.cut])
  x  bins
1   1.0   0-5
2   2.0   0-5
3   6.0  5-10
4   8.0  5-10
5  13.0 10-15
6   0.0   0-5
7   5.0   0-5
8  10.0  5-10
9  75.85256 75-80
10 38.20424 35-40
11 77.30647 75-80
12 62.02278 60-65
13 73.42095 70-75
14 78.69244 75-80
15 66.52972 65-70
16 61.64897 60-65
17 23.99252 20-25
18 42.08632 40-45


On 7/20/07, João Fadista [EMAIL PROTECTED] wrote:
 Dear all,

 I would like to know how can I create a binned column in a data.frame. The 
 output that I would like is something like this:

 Start  Binned_Start
 10-5
 20-5
 65-10
 85-10
 13  10-15
 ...




 Best regards

 João Fadista
 Ph.d. student



 UNIVERSITY OF AARHUS
 Faculty of Agricultural Sciences
 Dept. of Genetics and Biotechnology
 Blichers Allé 20, P.O. BOX 50
 DK-8830 Tjele

 Phone:   +45 8999 1900
 Direct:  +45 8999 1900
 E-mail:  [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 Web: www.agrsci.org http://www.agrsci.org/
 

 News and news media http://www.agrsci.org/navigation/nyheder_og_presse .

 This email may contain information that is confidential. Any use or 
 publication of this email without written permission from Faculty of 
 Agricultural Sciences is not allowed. If you are not the intended recipient, 
 please notify Faculty of Agricultural Sciences immediately and delete this 
 email.


[[alternative HTML version deleted]]


 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] binned column in a data.frame

2007-07-20 Thread David Katz

Would cut meet your needs?


João Fadista wrote:
 
 Dear all,
  
 I would like to know how can I create a binned column in a data.frame. The
 output that I would like is something like this: 
  
 Start  Binned_Start
 10-5
 20-5
 65-10
 85-10
 13  10-15
 ...
  
  
  
 
 Best regards
 
 João Fadista
 Ph.d. student
 
 
   
UNIVERSITY OF AARHUS   
 Faculty of Agricultural Sciences  
 Dept. of Genetics and Biotechnology   
 Blichers Allé 20, P.O. BOX 50 
 DK-8830 Tjele 
   
 Phone: +45 8999 1900  
 Direct:+45 8999 1900  
 E-mail:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]   
 Web:   www.agrsci.org http://www.agrsci.org/
 
 
 News and news media http://www.agrsci.org/navigation/nyheder_og_presse .
 
 This email may contain information that is confidential. Any use or
 publication of this email without written permission from Faculty of
 Agricultural Sciences is not allowed. If you are not the intended
 recipient, please notify Faculty of Agricultural Sciences immediately and
 delete this email.
 
 
   [[alternative HTML version deleted]]
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/binned-column-in-a-data.frame-tf4115787.html#a11717127
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.