Search code examples
j

Plotting a column of precision floating point values


I have a sequence of data that I have modified to the following:

load 'tables/csv'
load 'graphics/plot'
x =: readcsv 'table_ctl.csv'
dat =: 4 {::|:x 
dat

The data in question is pulling the fourth column, that has been transposed of the following sequence of the array. Below is a sample of the first five values for the column.

13.5598 13.6815 14.027 14.132 14.0104

However upon running:

plot dat

I get the following error:

|option not found: 13.5598: signal
|       signal'option not found: ',j

Is this error due to the precision of the floating point values? Thank you.


Solution

  • You're getting this error as you're passing a list of boxes to plot, and plot is expecting some of these boxes to contain the data to plot, and some other boxes to contain control data. 13.5598 is not a valid option for a plot.

       fread 'table_ctl.csv'
    a,b,0,1,13.5598
    a,b,0,1,13.6815
    a,b,0,1,14.027
    a,b,0,1,14.132
    a,b,0,1,14.0104
    
       4 {::|: readcsv 'table_ctl.csv'
    ┌───────┬───────┬──────┬──────┬───────┐
    │13.5598│13.6815│14.027│14.132│14.0104│
    └───────┴───────┴──────┴──────┴───────┘
    

    Probably you were thinking that {:: automatically unboxes, but it only does this if the path you give it designates a single box. See the top text at Fetch. The other problem to have is that the contents of these boxes are strings, not floats:

       $ > 4 {::|: readcsv 'table_ctl.csv'
    5 7
       |."1 > 4 {::|: readcsv 'table_ctl.csv'
    8955.31
    5186.31
     720.41
     231.41
    4010.41
    

    So, to plot your numbers: plot > makenum 4 {::|: readcsv 'table_ctl.csv' which starts with the list of boxes, then turns each box into a box of a float, then unboxes the list and plots it. makenum comes with readcsv and is like a smart ". each in this case, as it would leave non-numeric boxes alone.

    There's a bit more to set up, but jd might also work for this:

       fread 'table_ctl.cdefs'
     1 label    byte 1
     2 name     varbyte
     3 enabled  boolean
     4 weight   int
     5 score    float
    options , LF NO \ 0 iso8601-char
    
       load 'data/jd'
    !!! Jd key: non-commercial use only!
       jdwelcome_jd_ NB. run this sentence for important information
    
       jdadminnew'temp'
       CSVFOLDER=:'/path/to/csv/directory'
       jd'csvrd table_ctl.csv data'
       jd'info schema'
    ┌─────┬───────┬───────┬─────┐
    │table│column │type   │shape│
    ├─────┼───────┼───────┼─────┤
    │data │label  │byte   │1    │
    │data │name   │varbyte│_    │
    │data │enabled│boolean│_    │
    │data │weight │int    │_    │
    │data │score  │float  │_    │
    └─────┴───────┴───────┴─────┘
       jd'get data score'
    13.5598 13.6815 14.027 14.132 14.0104