对此的任何帮助都将非常感激。
我有A和B,并希望将AB作为A或B的最大值并考虑到NA
A<-c(1,1,1,0,0,0,NA,NA,NA)
B<-c(1,0,NA,1,0,NA,1,0,NA)
AB<-c(1,1,1,1,0,0,1,0,NA)
TEST<-cbind(A,B,AB)
A B AB
[1,] 1 1 1
[2,] 1 0 1
[3,] 1 NA 1
[4,] 0 1 1
[5,] 0 0 0
[6,] 0 NA 0
[7,] NA 1 1
[8,] NA 0 0
[9,] NA NA NA
答案 0 :(得分:4)
将public static int[] replicate(int[] arr, int n) {
int[] temp = new int[arr.length];
int current=0;
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (count%n!=0){
temp[count] = arr[i];
count++;
}
}
int[] whitelist = new int[count];
System.arraycopy(temp, 0, whitelist, 0, count);
return whitelist;
}
功能与pmax()
:
na.rm=TRUE