sum only the negative values in a row from an xts-object
问题 I have an xts-object and I want to sum only the negative values in the first row. The code sum(test[test<0]) gives me the error Error in `[.xts`(test, test < 0) : 'i' or 'j' out of range but sum(test[1],na.rm=TRUE) works, but then I have the sum of all the values, not just the negative ones: [1] -0.9786889 Without giving an example of data yet, does anybody know why this simple code doesnt work? The dimension of the xts-object is > dim(test) is 216 39 . 回答1: There is a chance that this is