r - Printing values inside for loop gives different results if you print by index or by value -
i'm trying understand why different results when print values of list when access them index or directly:
ws <- c(as.date('2016-01-01')) (w in ws) { print(w) } # prints 16801 (idx in 1:length(ws)) { print(ws[idx]) } # prints 2016-01-01 i'm not sure why first time, when access value using in wrong value.
how can print values directly accessing via in (not using indexes)? , why happening?
probably because ws integer; "date" see printing purposes, data tracked days since starting point.
when create indexing variable w in ws, r coercing integer w has lost "date" attributes, , underlying integer.
indeed, in ?control see seq:
an expression evaluating vector (including list , expression) or pairlist or null. factor value coerced character vector.
and as.vector(ws) return ws it's underlying, integer, state.
in second example, ws has remained unchanged, printing elements continue formatted dates.
Comments
Post a Comment