English 中文(简体)
需求帮助配对数据
原标题:Need help pairing data
  • 时间:2012-05-02 12:00:32
  •  标签:
  • r

我看一下我确信的答案。 我用一个数据集来研究:

    Week      Game.ID           VTm VPts HTm HPts Differential HomeWin 
    1  NFL_20050908_OAK@NE      OAK   20 NE  30           10   TRUE 
    1 NFL_20050911_ARI@NYG      ARI   19 NYG 42           23   TRUE 
    1 NFL_20050911_CHI@WAS      CHI    7 WAS 9            2    TRUE 
    1 NFL_20050911_CIN@CLE      CIN   27 CLE 13          -14   FALSE 
    1  NFL_20050911_DAL@SD      DAL   28 SD  24           -4   FALSE 
    1 NFL_20050911_DEN@MIA      DEN   10 MIA 34           24   TRUE 

NFL数据。 我希望能找到一条途径,使吉大港山区与它的不同之处相配,并将这些价值存放在另一个桌子上。 我知道这样做是容易的,但我提出的所有方法都涉及通过寻找[i,5]=“NE”的通道单独进行每个小组的工作。 我很想知道,所有32个小组是否有办法系统地这样做。 然后,我将使用同样的方法,将同一个团队代码(“NYG”或“NE”)与VPTs和VDifferential相配。

得到帮助。

问题回答

不要确定我是否正确理解你的问题(你需要像在数据库中选择这样的职能?)但:

cbind(matr[,x], matr[,y])

选择X栏和x,并创建新的矩阵

如同你一样,它希望根据一组变量在你的数据框架内开展行动。 为此,有许多职能,其中包括<编码>tapply()。 例如,如果你的数据属于数据。 标号为<代码>nflDF的标的,请在每一家小组<代码>上填写<>Differential。 HTm

tapply(nflDF$Differential, nflDF$HTm, FUN = max)

Which would return (with your sample data)

CLE MIA  NE NYG  SD WAS 
-14  24  10  23  -4   2

或者,您可使用<代码>by:

by(nflDF, nflDF$HTm, FUN = function(x) max(x$Differential))

HTm: CLE
[1] -14
------------------------------------------------------------ 
HTm: MIA
[1] 24
------------------------------------------------------------ 
HTm: NE
[1] 10
------------------------------------------------------------ 
HTm: NYG
[1] 23
------------------------------------------------------------ 
HTm: SD
[1] -4
------------------------------------------------------------ 
HTm: WAS
[1] 2

为了开展更为复杂的业务,在适当职能中改变向<代码>FUN提供的价值。





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

热门标签