R: How to replace elements of a data.frame?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-04T16:47:06Z
Indexed on
2010/05/04
17:28 UTC
Read the original article
Hit count: 126
I'm trying to replace elements of a data.frame containing "#N/A" with "NULL", and I'm running into problems:
foo <- data.frame("day"= c(1, 3, 5, 7), "od" = c(0.1, "#N/A", 0.4, 0.8))
indices_of_NAs <- which(foo == "#N/A")
replace(foo, indices_of_NAs, "NULL")
Error in [<-.data.frame
(*tmp*
, list, value = "NULL") :
new columns would leave holes after existing columns
I think that the problem is that my index is treating the data.frame as a vector, but that the replace function is treating it differently somehow, but I'm not sure what the issue is?
© Stack Overflow or respective owner