I have an xts object test
.
For a specific column, setting all values in year 2009
to NA
test$row1["2009"] <- NA
works like a charm, but if test
has several columns, why does
test["2009"] <- NA
only set the values in 2009 from the first column to NA
? I want that it sets all values in 2009
to NA for every column.
Do I really have to use a loop/ apply here or is there an easier option?
The solution is simple, leave the column index empty:
test["2009", ] <- NA
This will cause all columns to be indexed. And just row "2009"
.