[R] addition in the initial question [SCL:4]
arun
smartpink111 at yahoo.com
Mon Feb 18 22:42:59 CET 2013
Hi Elisa,
I think your question is regarding "why the third column (Frequency) is absent??
aggregate(row.names(dat1)~class,dat1,function(x) x)[1] #Here, the first two class are not there, because it was not in the dataset. (0.1<x<=0.2) was not there and (0<x<=0.1) is also not present, eventhough 0 was present, but our class should be >0.
# class
#1 0.2<x<=0.3
#2 0.3<x<=0.4
#3 0.4<x<=0.5
#4 0.5<x<=0.6
#5 0.6<x<=0.7
#6 0.7<x<=0.8
#7 0.8<x<=0.9
#8 0.9<x<=1
vecNew1<-as.data.frame(table(vecNew))
# vecNew Freq
#1 0<x<=0.1 0
#2 0.1<x<=0.2 0
#3 0.2<x<=0.3 15
#4 0.3<x<=0.4 24
#5 0.4<x<=0.5 27
#6 0.5<x<=0.6 20
#7 0.6<x<=0.7 15
#8 0.7<x<=0.8 12
#9 0.8<x<=0.9 9
#10 0.9<x<=1 1
res1<- data.frame(aggregate(row.names(dat1)~class,dat1,function(x) x),Frequency=as.data.frame(table(vecNew))[-c(1,2),2]) #first two classes were not present
names(vecNew1)<-names(res1)[c(1,3)]
library(plyr)
join(vecNew1,res1,by=c("class","Frequency"),type="full")
# class Frequency
#1 0<x<=0.1 0
#2 0.1<x<=0.2 0
#3 0.2<x<=0.3 15
#4 0.3<x<=0.4 24
#5 0.4<x<=0.5 27
#6 0.5<x<=0.6 20
#7 0.6<x<=0.7 15
#8 0.7<x<=0.8 12
#9 0.8<x<=0.9 9
#10 0.9<x<=1 1
# row.names.dat1.
#1 NULL
#2 NULL
#3 2, 10, 14, 32, 34, 36, 70, 85, 95, 99, 101, 103, 104, 113, 120
#4 8, 45, 46, 51, 54, 57, 58, 60, 61, 63, 67, 78, 86, 87, 88, 91, 92, 96, 97, 102, 110, 114, 115, 124
#5 11, 12, 15, 20, 27, 30, 33, 35, 48, 53, 55, 59, 68, 69, 71, 74, 77, 81, 82, 83, 89, 90, 93, 98, 105, 107, 121
#6 4, 13, 17, 18, 21, 23, 24, 25, 28, 29, 31, 37, 43, 47, 62, 64, 65, 94, 100, 111
#7 3, 16, 38, 41, 42, 50, 52, 72, 80, 84, 106, 108, 117, 118, 122
#8 5, 6, 7, 9, 39, 40, 73, 76, 79, 109, 112, 116
#9 19, 22, 26, 44, 49, 56, 66, 75, 123
#10 119
A.K.
________________________________
From: eliza botto <eliza_botto at hotmail.com>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com>
Sent: Monday, February 18, 2013 4:10 PM
Subject: RE: [R] addition in the initial question [SCL:4]
Thanks arun,
here it is
vec1<-c(gg)
vec2<-vec1[1:124]
names(vec2)<-(1:124)
label1<-unlist(lapply(mapply(c,lapply(seq(0,0.90,0.1),function(x) x),lapply(seq(0.1,1,0.1),function(x) x),SIMPLIFY=FALSE),function(i) paste(i[1],"<x<=",i[2],sep="")))
dat1<-data.frame(vec2,class=cut(vec2,breaks=seq(0,1,0.1),labels=label1),stringsAsFactors=FALSE)
vecNew<-cut(vec2,breaks=seq(0,1,0.1),labels=label1)
res<-as.data.frame(aggregate(row.names(dat1)~class,dat1,function(x) x),Frequency=as.data.frame(table(vecNew))[,3],stringsAsFactors=FALSE)
names(res)[2]<- "header_elements_class"
thankyou so very much.
stay blessed
elisa
> Date: Mon, 18 Feb 2013 13:02:35 -0800
> From: smartpink111 at yahoo.com
> Subject: Re: [R] addition in the initial question [SCL:4]
> To: eliza_botto at hotmail.com
>
> Hi Elisa,
>
> Here the vector length >26. But, in the previous example the length was 26 and it was named with letters.
>
> Also, here, the class categories should be different, right?
>
> max(gg)
> #[1] 0.95019
>
> So, I am assuming you made some changes to the code. Could you email the code you used and also the different categories of class?
> Arun
>
>
>
>
>
> ________________________________
> From: eliza botto <eliza_botto at hotmail.com>
> To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com>
> Sent: Monday, February 18, 2013 3:08 PM
> Subject: RE: [R] addition in the initial question [SCL:4]
>
>
>
> Dear Arun,
> Thanks for your kind advice. But unfortunatly, its not working with my data.
>
> > dput(gg)
> c(0, 0.28189, 0.6639, 0.5154, 0.77667, 0.70171, 0.78666, 0.34442,
> 0.72091, 0.23643, 0.44381, 0.45992, 0.59163, 0.25542, 0.48373,
> 0.64251, 0.54566, 0.5648, 0.84952, 0.42145, 0.54035, 0.88599,
> 0.59981, 0.57378, 0.59432, 0.82779, 0.46882, 0.54043, 0.59857,
> 0.40087, 0.55274, 0.28464, 0.4502, 0.24964, 0.44608, 0.21136,
> 0.58958, 0.64248, 0.70631, 0.70928, 0.61397, 0.65114, 0.57528,
> 0.82119, 0.33098, 0.31403, 0.51127, 0.49723, 0.80711, 0.6612,
> 0.33378, 0.64375, 0.45849, 0.32759, 0.44656, 0.84421, 0.32896,
> 0.31745, 0.48302, 0.3845, 0.3475, 0.57271, 0.3904, 0.54716, 0.56335,
> 0.86038, 0.37506, 0.48184, 0.47899, 0.2813, 0.47213, 0.6498,
> 0.79342, 0.46142, 0.85018, 0.73835, 0.40189, 0.33038, 0.7112,
> 0.6031, 0.47986, 0.49434, 0.48138, 0.69359, 0.25867, 0.33724,
> 0.37273, 0.3168, 0.44585, 0.48672, 0.39916, 0.3836, 0.41951,
> 0.58556, 0.20466, 0.31819, 0.30299, 0.41592, 0.25732, 0.57609,
> 0.29921, 0.31606, 0.29339, 0.21411, 0.47548, 0.67929, 0.43836,
> 0.6397, 0.7536, 0.31167, 0.56878, 0.79869, 0.26653, 0.33772,
> 0.38865, 0.70585, 0.64432, 0.66255, 0.95019, 0.28911, 0.48223,
> 0.69093, 0.84077, 0.3715)
>
> thanks alot
>
> eliza
>
> > Date: Sun, 17 Feb 2013 13:23:20 -0800
> > From: smartpink111 at yahoo.com
> > To: eliza_botto at hotmail.com
> > CC: r-help at r-project.org
> > Subject: Re: [R] addition in the initial question [SCL:4]
> >
> > Dear Elisa,
> > Try this:
> > vec1<-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45)
> > vec2<-vec1[1:26]
> > names(vec2)<-LETTERS[1:26]
> > label1<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i) paste(i[1],"<x<=",i[2],sep="")))
> > dat1<-data.frame(vec2,class=cut(vec2,breaks=seq(0,50,5),labels=label1),stringsAsFactors=FALSE)
> > vecNew<-cut(vec2,breaks=seq(0,50,5),labels=label1)
> > res<-data.frame(aggregate(row.names(dat1)~class,dat1,function(x) x),Frequency=as.data.frame(table(vecNew))[,2],stringsAsFactors=FALSE)
> > names(res)[2]<- "header_elements_class"
> > res
> > # class header_elements_class Frequency
> > #1 0<x<=5 P, R, X 3
> > #2 5<x<=10 F, G 4
> > #3 10<x<=15 C, M, S, Z 3
> > #4 15<x<=20 B, N, T 2
> > #5 20<x<=25 H, J 2
> > #6 25<x<=30 E, L 3
> > #7 30<x<=35 A, V, Y 3
> > #8 35<x<=40 I, K, W 2
> > #9 40<x<=45 O, Q 2
> > #10 45<x<=50 D, U 2
> > str(res)
> > #'data.frame': 10 obs. of 3 variables:
> > # $ class : Factor w/ 10 levels "0<x<=5","5<x<=10",..: 1 2 3 4 5 6 7 8 9 10
> > # $ header_elements_class:List of 10
> > # ..$ 0: chr "P" "R" "X"
> > # ..$ 1: chr "F" "G"
> > # ..$ 2: chr "C" "M" "S" "Z"
> > # ..$ 3: chr "B" "N" "T"
> > # ..$ 4: chr "H" "J"
> > # ..$ 5: chr "E" "L"
> > # ..$ 6: chr "A" "V" "Y"
> > # ..$ 7: chr "I" "K" "W"
> > # ..$ 8: chr "O" "Q"
> > # ..$ 9: chr "D" "U"
> > # $ Frequency : int 3 4 3 2 2 3 3 2 2 2
> >
> >
> > A.K.
> >
> >
> >
> >
> >
> > ________________________________
> > From: eliza botto <eliza_botto at hotmail.com>
> > To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com>
> > Sent: Sunday, February 17, 2013 3:27 PM
> > Subject: addition in the initial question
> >
> >
> >
> > Dear Arun,
> >
> > just a small change in the initial question.
> > what if, instead of counting number i want to get the headers of the numbers falling in each range. finally counting those numbers to get frequencies and then drawing histograms and fitting density curve.
> >
> > [HEADER] A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
> > [VECTOR] 33 18 13 47 30 10 6 21 39 25 40 29 14 16 44 1 41 4 15 20 46 32 38 5 31 12
> >
> >
> > classheader of elements in each class Frequency
> >
> > 0<x<=5P, R, X 3
> > 5<x<=10F, G 2
> > 10<x<=15 C, S 2
> > .....
> > ...
> > ...
> > ...
> > 45<x<=50 U 1
> >
> > thankyou very much in advance
> >
> > elisa
> >
> > ______________________________________________
> > 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.
More information about the R-help
mailing list