登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

云之南

风声,雨声,读书声,声声入耳;家事,国事,天下事,事事关心

 
 
 

日志

 
 
关于我

专业背景:计算机科学 研究方向与兴趣: JavaEE-Web软件开发, 生物信息学, 数据挖掘与机器学习, 智能信息系统 目前工作: 基因组, 转录组, NGS高通量数据分析, 生物数据挖掘, 植物系统发育和比较进化基因组学

R "\"字符 names rownames,colnames,Table  

2011-06-14 21:25:23|  分类: R&Bioconductor |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |


The backslash
(\) is known as the escape character. In a similar vein, you can insert quote
characters with \", as in

>cat("What is \"R\"?\n")
What is "R"?

> x <- c(red="Huey", blue="Dewey", green="Louie")
> x
red blue green
"Huey" "Dewey" "Louie"
> names(x)
[1] "red" "blue" "green"

> caff.marital <- matrix(c(652,1537,598,242,36,46,38,21,218
+ ,327,106,67),
+ nrow=3,byrow=T)
> caff.marital
[,1] [,2] [,3] [,4]
[1,] 652 1537 598 242
[2,] 36 46 38 21
[3,] 218 327 106 67
> colnames(caff.marital) <- c("0","1-150","151-300",">300")
> rownames(caff.marital) <- c("Married","Prev.married","Single")
> caff.marital
0 1-150 151-300 >300
Married 652 1537 598 242
Prev.married 36 46 38 21
Single 218 327 106 67

> names(dimnames(caff.marital)) <- c("marital","consumption")
> caff.marital
consumption
marital 0 1-150 151-300 >300
Married 652 1537 598 242
Prev.married 36 46 38 21
Single 218 327 106 67

you can convert to that matrices class using as.table(caff.marital) from "table".In that case, you should do the
tabulation with table, xtabs, or ftable

> as.data.frame(as.table(caff.marital))
marital consumption Freq
1 Married 0 652
2 Prev.married 0 36
3 Single 0 218
4 Married 1-150 1537
5 Prev.married 1-150 46
6 Single 1-150 327
7 Married 151-300 598
8 Prev.married 151-300 38
9 Single 151-300 106
10 Married >300 242
11 Prev.married >300 21
12 Single >300 67

margin.table(行求和)
> total.caff <- margin.table(caff.marital,2) 
> total.caff
consumption
0 1-150 151-300 >300
906 1910 742 330

prop.table(caff.marital)
BARPLOT图
> barplot(total.caff, col="white")
> par(mfrow=c(2,2))
> barplot(caff.marital, col="white")
> barplot(t(caff.marital), col="white")
#If you want to place the row contributions beside each other instead, you can use the argument beside=T

> barplot(t(caff.marital), col="white", beside=T)
> barplot(prop.table(t(caff.marital),2), col="white", beside=T)

> par(mfrow=c(1,1))
>barplot(prop.table(t(caff.marital),2),beside=T,
+ legend.text=colnames(caff.marital),
+ col=c("white","grey80","grey50","black"))

DOTCHART图
>dotchart(t(caff.marital), lcolor="black")

PIE图
> opar <- par(mfrow=c(2,2),mex=0.8, mar=c(1,1,2,1))
> slices <- c("white","grey80","grey50","black")
> pie(caff.marital["Married",], main="Married", col=slices)
> pie(caff.marital["Prev.married",],
+ main="Previously married", col=slices)
> pie(caff.marital["Single",], main="Single", col=slices)
> par(opar)
  评论这张
 
阅读(2065)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018