[R] A question about embedded R
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Tue Apr 6 12:59:07 CEST 2004
Song Baiyi <song.baiyi at udo.edu> writes:
> for(i = 0; i < n ; i++)
> val = (double)REAL(eval(VECTOR_ELT(e,i), R_GlobalEnv))[0];
...
> eval_R_command("mean(1:5)")
> it worked fine and got 3,
>
> but
>
> eval_R_command("sum(1:5)")
> it produced a strange number 7.41098e-323! not 15
>
> What is the problem?
You have a sum of integers, so the result is integer and you access it
as a REAL. You need explicit coercion, or to use
eval_R_command("as.double(sum(1:5))")
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list