私はRを使用しています。各プレーヤの行と、各月の数値と得点の数からなるデータフレームがあります以下のランダム値)。私は、過去5ヶ月間にわたって指定されたポイント合計の最長連続ストリークを含む新しい列(Points $ ConsecutiveShutouts)を追加したいと思います。 Iは、RLE(ポイント)を使用して試みたR:RLEを使用して列間で連続する同一の値の数
Points <- data.frame("Player" = c("Alpha", "Beta", "Charlie", "Delta", "Echo", "Foxtrot", "Gamma"), "MayPts" = c(floor(runif(7, 0, 3))), "JunPts" = c(floor(runif(7, 0, 3))), "JulPts" = c(floor(runif(7, 0, 3))), "AugPts" = c(floor(runif(7, 0, 3))), "SepPts" = c(floor(runif(7, 0, 3))), "OctPts" = c(floor(runif(7, 0, 3))), "NovPts" = c(floor(runif(7, 0, 3))),"DecPts" = c(floor(runif(7, 0, 3))))
Player MayPts JunPts JulPts AugPts SepPts OctPts NovPts DecPts
Alpha 0 0 1 0 2 2 2 0
Beta 1 0 1 1 1 1 1 2
Charlie 1 2 2 0 2 1 1 0
Delta 0 1 1 2 2 2 0 0
Echo 1 1 0 2 1 2 0 1
Foxtrot 1 0 0 0 0 0 2 1
Gamma 2 0 1 1 0 2 0 1
:
これを行う# Establish the start and end months
StartMonth <- which(colnames(Points) == "SepPts")
EndMonth <- which(colnames(Points) == "DecPts")
# Find total of consecutive months with 0 points
Points$ConsecutiveShutOuts <- max(rel(Points[ ,StartMonth:EndMonth] == 0), lengths[!values])
、私はエラーで終わる " 'X' 原子型のベクトルでなければなりません"
任意私が間違ってやっていることや、どうすれば修正できるのかアドバイスまたは代替アプローチ?
ありがとうございます! [初心者は、うまくいけば質問の質問に正しいアプローチに従った] :)
これはちょうど3列の '長い'データセットを持っていると、作業がはるかに簡単です - 1)Player 2)Month 3)Pts - 'rle'などを' Pts'カラムのみである。 – thelatemail