我有以下数据框:
df <- structure(list(Date = c("20-10-2014", "20-11-2014", "21-11-2014",
"22-10-2014", "23-10-2014", "24-10-2014", "25-10-2014", "26-10-2014"
), Team = c("Bulls", "Bulls", "Bulls", "Bulls", "Bulls", "Bulls",
"Bulls", "Bulls"), Result = c("W", "W", "W", "L", "L", "W", "W",
"L")), .Names = c("Date", "Team", "Result"), class = "data.frame", row.names = c(NA,
-8L))
其中我用'&#34;连胜&#34; &gt; 3使用这个公式
which(rep(rle(df$Result)$lengths,rle(df$Result)$lengths)>2)
现在我想指定使用1来满足winsstreak标准的行。
我知道我能做到:
list <- which(rep(rle(df$Result)$lengths,rle(df$Result)$lengths)>2)
然后
df <- df[list,]
获取值,但我正在寻找一种方法来为列表中的行指定1,为其他行指定0。
df$point <- ifelse(df[list, ], "1", "0")
这不起作用。有什么想法吗?