I nave no strong opinion, but
dealing with factors in R is
very simple:
foreign language=R
set.seed(13)
y <- rnorm(10)
x <- sample(3,10,replace=T)
lm(y~x)
lm(y~factor(x))
xch <- as.character(x)
print(xch)
lm(y~xch)
end foreign
As for me, the most tedious thing
with Main/Tools/Start GNU R
are time series
In this case class(gretldata)->"mts"
That's why I never use Tools/Start GNU R
with time series: instead I run the following
R script from gretl
<R
# choose interactive R session
if (any(class(gretldata)!="data.frame"))
{mts2frame2<-function(x)
{ddd<-data.frame(x);
if (length(class(x))>1)
{m<-ncol(x);for (i in 1:m)
ddd[,i]<-ts(ddd[,i],start=start(x),frequency=frequency(x))}
else
ddd[,1]<-ts(ddd[,1],start=start(x),frequency=frequency(x));
ddd};
gretldata<-mts2frame2(gretldata)}
# make native gretl variables names searcheable
attach(gretldata)
R>
In this case gretldata becomes a data.frame
with its columns retaining dates and frequencies
Oleh
14 вересня 2017, 00:20:54, від "Allin Cottrell" <cottrell(a)wfu.edu>:
> On Wed, 13 Sep 2017, Riccardo (Jack) Lucchetti wrote:
> I was thinking that we might want to map what we call "discrete"
> series into what R calls "factors". The idea is quite simple, and
> exemplified in the script below. My question to the list is: is
> this a good idea? Is it worth the coding effort (very small IMO)?
>
> Comments welcome.
>
> <hansl>
> nulldata 50
>
> cont1 = normal()
> cont2 = normal()
> disc1 = floor(uniform(1,5))
> disc2 = floor(uniform(4,18))
>
> discrete disc1 disc2
>
> list D = dataset
> loop foreach i D
> if !isdiscrete($i)
> D -= $i
> endif
> endloop
>
> matrix mD = D
> mwrite(mD, "discrete.mat", 1)
>
> foreign language=R --send-data
> D <- gretl.loadmat("discrete.mat");
> for (i in D) {gretldata[,i] <- as.factor(gretldata[,i])};
> summary(gretldata);
> end foreign
> </hansl>
Not sure about this, but my initial reaction is that it may be
assuming too much about our "discrete" series.
In R, isn't a "factor" a variable that (in gretl parlance) has to be
"dummified" before use in regression? That is, an arbitrary
encoding of a qualitative characteristic?
If so, then I think the above is wrong, since a gretl-discrete
series could be a perfectly valid (albeit quantized) quantitative
variable; for example, years of education or number of bedrooms.
But If I'm wrong about what a "factor" is to R, my objection may
fall.
Allin
_______________________________________________
Gretl-devel mailing list
Gretl-devel@lists.wfu.eduhttp://lists.wfu.edu/mailman/listinfo/gretl-devel