TRUE
并且FALSE
分别是1
,0
所以你应该能够做到这一点......
C <- ( A > B ) + 0
要排除第一列,只需[
像这样对其进行子集化:
C <- ( A[,-1] > B[,-1] ) + 0
例如:
A <- data.frame( Date1 = as.POSIXct( Sys.Date()+101:105 ) , Date2 = as.POSIXct( Sys.Date()-1001:1005 ) )
# Date1 Date2
#1 2013-12-13 2010-12-07
#2 2013-12-14 2010-12-06
#3 2013-12-15 2010-12-05
#4 2013-12-16 2010-12-04
#5 2013-12-17 2010-12-03
B <- data.frame( Date1 = as.POSIXct( Sys.Date()+106:110 ) , Date2 = as.POSIXct( Sys.Date()-1006:1010 ) )
# Date1 Date2
#1 2013-12-18 2010-12-02
#2 2013-12-19 2010-12-01
#3 2013-12-20 2010-11-30
#4 2013-12-21 2010-11-29
#5 2013-12-22 2010-11-28
C <- ( A > B ) + 0
# Date1 Date2
#[1,] 0 1
#[2,] 0 1
#[3,] 0 1
#[4,] 0 1
#[5,] 0 1