Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.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
在行计算(Dplyr)中选择整列(但已过滤)_R_Dplyr - Fatal编程技术网

在行计算(Dplyr)中选择整列(但已过滤)

在行计算(Dplyr)中选择整列(但已过滤),r,dplyr,R,Dplyr,以下基本计算的正确Dplyr管道是什么 dat <- data.frame(a = 0:10, b = 0:10, c = 0:10) dat$d <- apply(dat, 1, sum) ind <- dat$d>quantile(dat$d[dat$d>0], 0.1) dat% 变异(d=sum(c_横跨(a:c)),ind=d>分位数(select_var(d>0),0.1))%>% 拉力(ind) 提供与您的ind相同的值。

以下基本计算的正确Dplyr管道是什么

dat      <- data.frame(a = 0:10, b = 0:10, c = 0:10)
dat$d    <- apply(dat, 1, sum)
ind      <- dat$d>quantile(dat$d[dat$d>0], 0.1)
dat%
变异(d=sum(c_横跨(a:c)),ind=d>分位数(select_var(d>0),0.1))%>%
拉力(ind)
提供与您的
ind
相同的值。稍微有点困难是因为您是基于数据帧的子集而不是其整体性来计算分位数的


提供与您的
ind
相同的值。稍微有点困难是因为您是基于数据帧的子集而不是其完整性来计算分位数的。

您可以使用
$
来执行此操作,以便为整个数据返回
分位数

dat %>% rowwise() %>% 
  mutate(d = sum(c_across(a:c))) %>% 
  mutate(ind = d > quantile(.$d[.$d >0], 0.1))

    a  b  c  d   ind
1   0  0  0  0 FALSE
2   1  1  1  3 FALSE
3   2  2  2  6  TRUE
4   3  3  3  9  TRUE
5   4  4  4 12  TRUE
6   5  5  5 15  TRUE
7   6  6  6 18  TRUE
8   7  7  7 21  TRUE
9   8  8  8 24  TRUE
10  9  9  9 27  TRUE
11 10 10 10 30  TRUE
检查在
d
之前不添加
$
的情况下,是否会得到不想要的结果

dat %>% rowwise() %>% 
  mutate(d = sum(c_across(a:c))) %>% 
  mutate(ind = d > quantile(d[d >0], 0.1))

# A tibble: 11 x 5
# Rowwise: 
       a     b     c     d ind  
   <int> <int> <int> <int> <lgl>
 1     0     0     0     0 NA   
 2     1     1     1     3 FALSE
 3     2     2     2     6 FALSE
 4     3     3     3     9 FALSE
 5     4     4     4    12 FALSE
 6     5     5     5    15 FALSE
 7     6     6     6    18 FALSE
 8     7     7     7    21 FALSE
 9     8     8     8    24 FALSE
10     9     9     9    27 FALSE
11    10    10    10    30 FALSE
dat%>%rowwise()%>%
变异(d=总和(c_穿过(a:c)))%>%
变异(ind=d>分位数(d[d>0],0.1))
#A tibble:11 x 5
#顺时针:
a b c d ind
100NA
2 1 3错误
3 2 6错误
4 3 9错误
5 4 12错误
6515错误
7 6 18错误
8721错误
9824错误
109927错误
1101030错误

您可以使用
$
执行此操作,以便为整个数据返回
分位数

dat %>% rowwise() %>% 
  mutate(d = sum(c_across(a:c))) %>% 
  mutate(ind = d > quantile(.$d[.$d >0], 0.1))

    a  b  c  d   ind
1   0  0  0  0 FALSE
2   1  1  1  3 FALSE
3   2  2  2  6  TRUE
4   3  3  3  9  TRUE
5   4  4  4 12  TRUE
6   5  5  5 15  TRUE
7   6  6  6 18  TRUE
8   7  7  7 21  TRUE
9   8  8  8 24  TRUE
10  9  9  9 27  TRUE
11 10 10 10 30  TRUE
检查在
d
之前不添加
$
的情况下,是否会得到不想要的结果

dat %>% rowwise() %>% 
  mutate(d = sum(c_across(a:c))) %>% 
  mutate(ind = d > quantile(d[d >0], 0.1))

# A tibble: 11 x 5
# Rowwise: 
       a     b     c     d ind  
   <int> <int> <int> <int> <lgl>
 1     0     0     0     0 NA   
 2     1     1     1     3 FALSE
 3     2     2     2     6 FALSE
 4     3     3     3     9 FALSE
 5     4     4     4    12 FALSE
 6     5     5     5    15 FALSE
 7     6     6     6    18 FALSE
 8     7     7     7    21 FALSE
 9     8     8     8    24 FALSE
10     9     9     9    27 FALSE
11    10    10    10    30 FALSE
dat%>%rowwise()%>%
变异(d=总和(c_穿过(a:c)))%>%
变异(ind=d>分位数(d[d>0],0.1))
#A tibble:11 x 5
#顺时针:
a b c d ind
100NA
2 1 3错误
3 2 6错误
4 3 9错误
5 4 12错误
6515错误
7 6 18错误
8721错误
9824错误
109927错误
1101030错误