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 动物园中的基本条件数据选择_R_Zoo - Fatal编程技术网

R 动物园中的基本条件数据选择

R 动物园中的基本条件数据选择,r,zoo,R,Zoo,我有一个动物园“z”。有人能解释一下为什么我请求哪个(z[2,]>0&z[1,]>0)在我加载zoo库后不再工作了 > str(z) zoo [1:2, 1:12] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : NULL - attr(*, "index")=Classes 'dates', 'times' atomic [1:2] 17531 17562 .. ..-

我有一个动物园“z”。有人能解释一下为什么我请求
哪个(z[2,]>0&z[1,]>0)
在我加载zoo库后不再工作了

> str(z)
 zoo [1:2, 1:12] 0 0 0 0 0 0 0 0 0 0 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : NULL
 - attr(*, "index")=Classes 'dates', 'times'  atomic [1:2] 17531 17562
  .. ..- attr(*, "format")= chr "m/d/y"
  .. ..- attr(*, "origin")= Named num [1:3] 1 1 1970
  .. .. ..- attr(*, "names")= chr [1:3] "month" "day" "year"

> which(z[2,]>0 & z[1,]>0)
[1] 12

> library(zoo)

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric


> which(z[2,]>0 & z[1,]>0)
integer(0)
有兴趣的人士:

> dput(z)
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0.00996714478550151, 0.00996009385006366), .Dim = c(2L, 
12L), .Dimnames = list(NULL, NULL), index = structure(c(17531, 
17562), format = "m/d/y", origin = structure(c(1, 1, 1970), .Names = c("month", 
"day", "year")), class = c("dates", "times")), class = "zoo")

它将尝试合并z[1]和z[2],以实现这一点&但它们没有共同的时间

您可以尝试以下方法之一:

library(zoo)

## 1
which(apply(z > 0, 2, all))

## 2 
which(pmin(z[1, ], z[2, ]) > 0)

## 3
which(colSums(z > 0) == nrow(z))

## 4
which(apply(z, 2, min) > 0)

## 5
cz <- coredata(z)
which(cz[1, ] > 0 & cz[2, ] > 0)

# 6
library(matrixStats)
which(colAlls(z > 0))
图书馆(动物园)
## 1
其中(应用(z>0,2,全部))
## 2 
其中(pmin(z[1,],z[2,])>0)
## 3
其中(colSums(z>0)=nrow(z))
## 4
其中(应用(z,2,min)>0)
## 5
cz 0和cz[2,]>0)
# 6
图书馆(matrixStats)
哪个(colall(z>0))

请分享dput(a)好吗。这可能有助于其他人理解您的数据,从而找出问题所在。我刚刚添加了这一点,这很奇怪,因为
哪个(a[2,]>0&a[1,]>0)
实际上是在给予
[12]
<代码>>其中((a[2,]>0)和(a[1,]>0))[1]12