Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.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 - Fatal编程技术网

R 问题汇总列

R 问题汇总列,r,R,我有一个非常大的数据集,我正试图得到值的总和。变量是二进制的,带有0和1 不知怎的,当我运行for循环时 for (i in 7:39){ agegroup1[53640, i]<-sum(agegroup1[, i]) } for(我在7:39){ 年龄组1[53640,i] 在开始添加列总和之前,agegroup1[53640,]中有什么内容?NA?如果是这样,可以解释一些行为 我们确实需要更多的细节 在开始添加列总和之前,agegroup1[53640,]中有什么内容?NA?如果是

我有一个非常大的数据集,我正试图得到值的总和。变量是二进制的,带有0和1

不知怎的,当我运行for循环时

for (i in 7:39){
agegroup1[53640, i]<-sum(agegroup1[, i])
}
for(我在7:39){
年龄组1[53640,i]
在开始添加列总和之前,
agegroup1[53640,]
中有什么内容?
NA
?如果是这样,可以解释一些行为

我们确实需要更多的细节

在开始添加列总和之前,
agegroup1[53640,]
中有什么内容?
NA
?如果是这样,可以解释一些行为


我们确实需要更多的细节,尽管…

@Gavin Simpson提供了一个可行的解决方案,但您也可以使用apply。此函数允许您将函数应用于行或列边距

x <- cbind(x1=1, x2=c(1:8), y=runif(8))

# If you wanted to sum the rows of columns 2 and 3
apply(x[,2:3], 1, sum, na.rm=TRUE)

# If you want to sum the columns of columns 2 and 3
apply(x[,2:3], 2, sum, na.rm=TRUE)

x@Gavin Simpson提供了一个可行的解决方案,但您也可以使用apply。此函数允许您将函数应用于行或列边距

x <- cbind(x1=1, x2=c(1:8), y=runif(8))

# If you wanted to sum the rows of columns 2 and 3
apply(x[,2:3], 1, sum, na.rm=TRUE)

# If you want to sum the columns of columns 2 and 3
apply(x[,2:3], 2, sum, na.rm=TRUE)

x您检查过要求和的列中的NA值吗?您可以用
any(is.NA(agegroup1))
检查
NA
s,您可以用
哪个(is.NA(agegroup1))
查看它们在哪里。您检查过要求和的列中的NA值吗?您可以用
any(is.NA(agegroup1))检查
NA
s
,您可以使用
查看它们的位置,即.na(agegroup1))
x <- cbind(x1=1, x2=c(1:8), y=runif(8))

# If you wanted to sum the rows of columns 2 and 3
apply(x[,2:3], 1, sum, na.rm=TRUE)

# If you want to sum the columns of columns 2 and 3
apply(x[,2:3], 2, sum, na.rm=TRUE)