I've been using ifelse
to assign a vector to a column of a dataframe, like this:
data[, ncol(data) + 1] <- ifelse(is.price, p, y)
(where p
and y
are vectors)
Unfortunately, I realized that this expression vectorizes the first element of ifelse
's return value, and so I get a column that's nrow(data)
identical elements. Is this a flaw of R, and should I just use a more explicit assignment?