English 中文(简体)
R——独一无二,还是我重复计算?
原标题:Cut function in R - exclusive or am I double counting?
  • 时间:2011-11-22 21:09:17
  •  标签:
  • r

https://stackoverflow.com/questions/7705336/grouping-on-multiple-variables-in-r” 我问,“Andrie”回答的是,我对“<条码>>执行/编码”功能和标签的使用有疑问。

我也希望得到基于用户记录次数范围的简要统计数据。

我的数据如下:

  # Get random numbers
  NumLogin <- round(runif(100,1,50))

  # Set the login range     
  LoginRange <- cut(NumLogin, 
       c(0,1,3,5,10,15,20,Inf), 
       labels=c( 1 , 2 , 3-5 , 6-10 , 11-15 , 16-20 , 20+ )
       )

现在我有我的LoginRange,但我不敢肯定,<条码>执行/编码”实际上如何运作。 我想找到在1次、2次、3-5次左右的用户,而只有用户在这种范围内。 <cut/code> function including 3 two (in the 2 bucket and the 3-5 bucket)? 如果我以我为例,我可以看到一个用户,他们有3次,但他们是<条码>执行/编码>。 我先看一下文件,然后看看每读一书,但无uck。 我做了什么错误?

另外,作为一个使用问题,我是否应当把LoginRange附在我的数据框架中? 如果是,这样做的最佳方式是什么?

DF <- data.frame(NumLogin, LoginRange)

?

增 编

最佳回答

<代码>cut(功能>界定的间隔(因缺省而终止)。 了解这意味着:

cut(1:2, breaks=c(0,1,2))
# [1] (0,1] (1,2]

As you can see, the integer 1 gets included in the range (0,1], not in the range (1,2]. It doesn t get double-counted, and for any input value falling outside of the bins you define, cut() will return a value of NA.

在处理按分类的数据时,我倾向于设定分类点between,只是为了避免自己出走。 事实上,根据你的数据(如下文所示),第2和第3版双目实际上被错误地点名,这非常令人 n笑 the!

LoginRange <- cut(NumLogin, 
   c(0.5, 1.5, 3.5, 5.5, 10.5, 15.5, 20.5, Inf),
   # c(0,1,3,5,10,15,20,Inf) + 0.5, 
   labels=c( 1 , 2-3 , 4-5 , 6-10 , 11-15 , 16-20 , 20+ )
   )
问题回答

暂无回答




相关问题
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 ...

热门标签