tag:blogger.com,1999:blog-8499895524521663926.post5696756309844373926..comments2024-03-27T07:13:39.236-04:00Comments on Phylogenetic Tools for Comparative Biology: R trick 1: get the frequencies of factors in a vectorLiam Revellhttp://www.blogger.com/profile/04314686830842384151noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8499895524521663926.post-52164848672795845462014-06-16T16:28:50.451-04:002014-06-16T16:28:50.451-04:00This is a hack:
x<-c(1,2,1,4,1,5,6,5,6,5,7)
su...This is a hack:<br /><br />x<-c(1,2,1,4,1,5,6,5,6,5,7)<br />summary(as.factor(sort(x)))<br /><br />Alternatively:<br /><br />obj<-hist(x,breaks=min(x):(max(x)+1)-0.5)<br />f<-setNames(obj$counts,obj$mids)<br />f<br /><br />The latter option also gives you any zeroes on the range of your integers.<br /><br />There may (of course) be some better way to do this that I'm not aware of.<br /><br />- LiamLiam Revellhttps://www.blogger.com/profile/04314686830842384151noreply@blogger.comtag:blogger.com,1999:blog-8499895524521663926.post-42690260916709842432014-06-16T15:20:53.094-04:002014-06-16T15:20:53.094-04:00but say i have a vector with numbers summary dosn&...but say i have a vector with numbers summary dosn't give me the frequencies it gives me the median, mean, min, max ect.<br />how do i get the Frequency?<br /><br />say for simplicity i have this vector: c(1,2,1,4,1,5,6,5,6,5,7)<br />the frequencies are: [1] 3, [2] 1, [4] 1, [5] 3, [6] 2, [7] 1<br />But how do i get R to tell me this?Anonymoushttps://www.blogger.com/profile/15773749668942513491noreply@blogger.comtag:blogger.com,1999:blog-8499895524521663926.post-63641887151376869862012-06-29T17:05:53.463-04:002012-06-29T17:05:53.463-04:00Neat! I never use factors much, now I might!Neat! I never use factors much, now I might!dwbapsthttps://www.blogger.com/profile/17606476387441191531noreply@blogger.comtag:blogger.com,1999:blog-8499895524521663926.post-35465906947405523882012-06-29T15:46:59.221-04:002012-06-29T15:46:59.221-04:00R trick 2 to follow.R trick 2 to follow.Liam Revellhttps://www.blogger.com/profile/04314686830842384151noreply@blogger.com