简体   繁体   English

程序R根据指定的多个因子级别创建数据直方图

[英]Program R create histogram of data from specified levels of multiple factors

I want to create histograms from selected data in a larger file. 我想从较大文件中的选定数据创建直方图。 Example data set structure as follows: 示例数据集结构如下:

Column headers(values)
Trip (1,2,3,4)
Site (1,2)
Year (2013, 2104)
Amount (values range from 1 - 100)

For example, what code do I use to plot a histogram of values from Amount of only data from Trip 1, Site 1, Year 2014 ? 例如,我使用什么代码来绘制Trip 1, Site 1, Year 2014的仅数据Amount的值直方图?

I got as far as hist(Amount[Trip=="1"]) , but I don't know how to further specify which data I want it to use. 我到了hist(Amount[Trip=="1"]) ,但是我不知道如何进一步指定我要使用的数据。

You probably are looking for & , which ANDs logical vectors componentwise: 您可能正在寻找& ,而AND逻辑向量是按分量排列的:

> nn <- 100
> Trip <- sample(1:4,nn,T)
> Site <- sample(1:2,nn,T)
> Amount <- runif(nn)
> hist(Amount[Trip==1 & Site==1])

Don't confuse & with && ! 不要混淆&&& Look at ?"&&" for more info. 查看?"&&"了解更多信息。

You may want to read "An Introduction to R", which should be available as PDF under the "Help" menu entry of your R GUI. 您可能需要阅读“ R简介”,它应该以PDF的形式出现在R GUI的“帮助”菜单项下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM