Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 带ifelse的聚合函数_R - Fatal编程技术网

R 带ifelse的聚合函数

R 带ifelse的聚合函数,r,R,我想为每个MemberID获取数据集中最早的一天。但是我需要在aggregate函数中执行ifelse来整理一些数据。因为有很多交易记录,但我只需要用户采用移动频道后最早的一个(mobile==“1”) 应该是这样的列表: MEMBERID Date 212 2009/04/20 .... > aggregate(OrderDate ~ MemberID, Mobile, subset = (Mobile == "1"), min) 您可以使用aggregate函数中

我想为每个
MemberID
获取数据集中最早的一天。但是我需要在
aggregate
函数中执行ifelse来整理一些数据。因为有很多交易记录,但我只需要用户采用移动频道后最早的一个(
mobile==“1”

应该是这样的列表:

MEMBERID   Date
212        2009/04/20
....
> aggregate(OrderDate ~ MemberID, Mobile, subset = (Mobile == "1"), min)

您可以使用
aggregate
函数中的
subset
参数来选择数据帧的某些部分。但是,您需要使用公式接口。以下是iris的一个示例:

> head(iris)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
> aggregate(Sepal.Length ~ Species, iris, subset = iris$Species %in% c("versicolor", "virginica"), min)
     Species Sepal.Length
1 versicolor          4.9
2  virginica          4.9
您尚未发布数据的dput(),但我认为它将是这样的:

MEMBERID   Date
212        2009/04/20
....
> aggregate(OrderDate ~ MemberID, Mobile, subset = (Mobile == "1"), min)
希望它能为您服务。

请说明您在数据、代码和预期结果方面的问题。通过阅读了解如何提出一个强有力的问题,从而获得有用的结果