An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121002/2a0fa062/attachment.pl>
add values in one column getting range from other column
4 messages · Sapana Lohani, arun, Rui Barradas
Hi,
I guess this is what you wanted:
dat1<-read.table(text="
Area Percent
456?????? 0
3400????? 10
79????????? 25
56?????????? 18
467???????? 0
67????????? 67
839??????? 85
1120????? 0
3482????? 85
",sep="",header=TRUE)
?aggregate(dat1$Percent, list(Area = dat1[,"Area"],Range=cut(dat1
?$Percent,breaks=c(-Inf,0, 25, 50, 75, 100),
?? labels=c("<=0", "0-25", "25-50", "50-75", ">75"))),function(x) x)
#? Area Range? x
#1? 456?? <=0? 0
#2? 467?? <=0? 0
#3 1120?? <=0? 0
#4?? 56? 0-25 18
#5?? 79? 0-25 25
#6 3400? 0-25 10
#7?? 67 50-75 67
#8? 839?? >75 85
#9 3482?? >75 85
A.K.
----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Tuesday, October 2, 2012 5:25 PM
Subject: [R] add values in one column getting range from other column
Hi,
My dataframe has two columns one with area and other with percent. How can i add the areas that are within a range of percentage??
My dataframe looks like
Area Percent
456?????? 0
3400????? 10
79????????? 25
56?????????? 18
467???????? 0
67????????? 67
839??????? 85
1120????? 0
3482????? 85
I want to add the area for values whose percent is <0, 0-25, 25-50, 50-75, >75. How can I do that???
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org 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.
HI,
Infact, there is no need for aggregate().
dat1$range<-cut(dat3$Percent,breaks=c(-Inf,0,25,50,75,100),labels=c("<=0","0-25","25-50","50-75",">75"))
?dat1
#? Area Percent range
#1? 456?????? 0?? <=0
#2 3400????? 10? 0-25
#3?? 79????? 25? 0-25
#4?? 56????? 18? 0-25
#5? 467?????? 0?? <=0
#6?? 67????? 67 50-75
#7? 839????? 85?? >75
#8 1120?????? 0?? <=0
#9 3482????? 85?? >75
A.K.
----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Tuesday, October 2, 2012 5:25 PM
Subject: [R] add values in one column getting range from other column
Hi,
My dataframe has two columns one with area and other with percent. How can i add the areas that are within a range of percentage??
My dataframe looks like
Area Percent
456?????? 0
3400????? 10
79????????? 25
56?????????? 18
467???????? 0
67????????? 67
839??????? 85
1120????? 0
3482????? 85
I want to add the area for values whose percent is <0, 0-25, 25-50, 50-75, >75. How can I do that???
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org 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.
Hello,
Maybe this time you've got it wrong, Arun. The op wants to sum the
areas, not just label them.
Using your code,
Range=cut(dat1$Percent, breaks=c(-Inf,0, 25, 50, 75, 100),
labels=c("<=0", "0-25", "25-50", "50-75", ">75"))
aggregate(Area ~ Range, data = dat1, FUN = sum)
# Range Area
#1 <=0 2043
#2 0-25 3535
#3 50-75 67
#4 >75 4321
Hope this helps,
Rui Barradas
Em 03-10-2012 01:43, arun escreveu:
Hi,
I guess this is what you wanted:
dat1<-read.table(text="
Area Percent
456 0
3400 10
79 25
56 18
467 0
67 67
839 85
1120 0
3482 85
",sep="",header=TRUE)
aggregate(dat1$Percent, list(Area = dat1[,"Area"],Range=cut(dat1
$Percent,breaks=c(-Inf,0, 25, 50, 75, 100),
labels=c("<=0", "0-25", "25-50", "50-75", ">75"))),function(x) x)
# Area Range x
#1 456 <=0 0
#2 467 <=0 0
#3 1120 <=0 0
#4 56 0-25 18
#5 79 0-25 25
#6 3400 0-25 10
#7 67 50-75 67
#8 839 >75 85
#9 3482 >75 85
A.K.
----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Tuesday, October 2, 2012 5:25 PM
Subject: [R] add values in one column getting range from other column
Hi,
My dataframe has two columns one with area and other with percent. How can i add the areas that are within a range of percentage??
My dataframe looks like
Area Percent
456 0
3400 10
79 25
56 18
467 0
67 67
839 85
1120 0
3482 85
I want to add the area for values whose percent is <0, 0-25, 25-50, 50-75, >75. How can I do that???
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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. ______________________________________________ R-help at r-project.org 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.