r - Converting from a Formula object to a list -
in r, iterate on formula object. r automatically converts formula parse tree, see no reason why shouldn't able iterate.
for example, f <- ~x + y
has elements f[[1]] = ~
, f[[2]] = x + y
. however, for(v in f) print(tostring(v))
not output
[1] "~" [1] "+, x, y"
as expect to. instead, gives error invalid for() loop sequence
.
if need manually, use for(i in 1:length(f)) print(tostring(f[[i]]))
produce correct output. however, know why first method not work.
Comments
Post a Comment