English 中文(简体)
查阅R图二的指数
原标题:get index of the histogram bin in R
  • 时间:2012-01-13 16:21:58
  •  标签:
  • r
  • bin

我的问题是:

我怎么能找到数字下降的gram本指数?

在马特拉布,解决办法是容易的。 HISTC从事以下工作:

[counts,bin] = histc(data,edges)

"bin" being what I am looking for.

但是,我是在R,而R并没有提议职能性的<代码>hist功能。 我认为,我可以采用一些法典行文(将一些东西用在<条码>>>、<条码>和<条码>和>;),但鉴于我需要做很多工作,我想找到一个更加棘手的解决办法。

自2006年以来 在R,我没有经历过,我希望能够找到一个trick的解决办法,以另一种方式解决这一问题。

最佳回答

The hist function will return the breakpoints between the bins if you do not already have them. You can then use the findInterval function to find which interval/bin each of your points falls into:

> tmp <- hist(iris$Petal.Width)
> findInterval(iris$Petal.Width, tmp$breaks)
  [1]  2  2  2  2  2  3  2  2  2  1  2  2  1  1  2  3  3  2  2  2  2  3  2  3  2
 [26]  2  3  2  2  2  2  3  1  2  2  2  2  1  2  2  2  2  2  4  3  2  2  2  2  2
 [51]  7  8  8  7  8  7  9  6  7  7  6  8  6  7  7  7  8  6  8  6 10  7  8  7  7
 [76]  7  7  9  8  6  6  6  7  9  8  9  8  7  7  7  7  7  7  6  7  7  7  7  6  7
[101] 13 10 11 10 12 11  9 10 10 13 11 10 11 11 13 12 10 12 12  8 12 11 11 10 11
[126] 10 10 10 11  9 10 11 12  8  7 12 13 10 10 11 13 12 10 12 13 12 10 11 12 10
> tmp2 <- .Last.value
> cbind( value=iris$Petal.Width, lower=tmp$breaks[tmp2], upper=tmp$breaks[tmp2+1])
       value lower upper
  [1,]   0.2   0.2   0.4
  [2,]   0.2   0.2   0.4
  [3,]   0.2   0.2   0.4
  [4,]   0.2   0.2   0.4
  [5,]   0.2   0.2   0.4
  [6,]   0.4   0.4   0.6
  [7,]   0.3   0.2   0.4
  [8,]   0.2   0.2   0.4
  [9,]   0.2   0.2   0.4
 [10,]   0.1   0.0   0.2
问题回答

为方便港务编码,有若干套R套(re)实施<编码>histc。 例如,





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签