Dataframes

Create and transform

df.lg provides a set of tools for working with dataframes in Logo, see the documentation in df.pdf.

Dataframes can be created using “csv.read” or with “df.create” – it checks variable names and number, data types names and number, missing values – as in the following example:

make "df df.create [num char num] (list se "id iseq 1 4 se "sex (rs.rep [female male] 2) [age 28 missing 35 40])

“df.print” shows the dataframe.

          id          sex          age
       <num>       <char>        <num>
        1.00       female        28.00
        2.00       female      missing
        3.00         male        35.00
        4.00         male        40.00

First task

We can now find a new solution to Rosetta Code’s first task.

First read data.csv data file:

make "df (csv.read "data.csv [num num num num num])

Then create the variable “SUM”

make "df df.map :df [(sum ?1 ?2 ?3 ?4 ?5)] [C1 C2 C3 C4 C5] "SUM 

and print the dataframe:

df.print :df 
          C1           C2           C3           C4           C5          SUM
       <num>        <num>        <num>        <num>        <num>        <num>
        1.00         5.00         9.00        13.00        17.00        45.00
        2.00         6.00        10.00        14.00        18.00        50.00
        3.00         7.00        11.00        15.00        19.00        55.00
        4.00         8.00        12.00        16.00        20.00        60.00