x1<-c(3,4,2,5,7,9)
x2<-c(2,4,3,9,11,7)
x<-data.frame(x1,x2)
t<-0
for(j in 1:2)
{
t[j]<-which((x[,j]>5))
}
运行出来的结果是
t
[1] 5 4
并且有Warning messages:
1: In t[j] <- which((x[, j] > 5)) :
number of items to replace is not a multiple of replacement length
2: In t[j] <- which((x[, j] > 5)) :
number of items to replace is not a multiple of replacement length
我想问用什么方法才能正确寻找每一列满足条件的第一个数的位置和大小