On Sun, 23 Jun 2019, Artur Tarassow wrote:
>> Thanks for the fix, Allin. However, why is a numeric vector
(element v4)
>> treated as a string array even though it comprises numeric values only? Is
>> there any way to import it is a matrix datatype or some way to transform
>> it to such a datatype using gretl?
>
> We don't know the type of elements in a JSON array, they could be anything.
> So the safest thing is to store them as strings.
I thought the distinction between numeric and string values depends on the
"-symbol:
Numeric: "A": [1,2,3]
String: "A": ["1","2","3"]
Fair point. But we're not parsing the JSON by hand, we're relying on
the json-glib library, and when we get a JSON node from that library
we don't know if its content was originally wrapped in quotes or
not. (But it's possible I'm missing something in the json-glib API;
I'll take another look.)
> But of course there's a way to convert from strings to
numerical values
> (assuming that makes sense) in gretl. Suppose that bundle b holds an
> element v4 which is a suitable array:
>
> <hansl>
> n = nelem(b.v4)
> matrix m = zeros(1, n)
> loop i=1..n -q
> m[i] = atof(b.v4[i])
> endloop
> m
> </hansl>
Ah, thanks for this example. I've never used the atof() function before.
sscanf() could also do the job (element by element). But it might be
nice to enable something like
matrix m
sscanf(S, "%m", m)
to scan an array of numeric strings (S) into a matrix in one go.
Allin