Is there a simple equivalent to R's rbind in lisp-stat?

77 views Asked by At

Basically the title. I need to parse a lot of CSVs into a dataframe, then shove them into a sql database. I've already written the relevant parsing code for a single data frame, and there's plenty of documentation on the site regarding how to handle going from a data frame to a sqllite file, but I need to merge the dataframes into one DB, and I figure the easiest way to do that will be via an Rbind equivalent.

Overall, I've tried concatenate, stack-rows, and a few other forms both on the sequence/simple-vector side of things, and the lisp-stat side of things with little to no luck, so any ideas would be seriously helpful.

1

There are 1 answers

3
CL-USER On

The way to do that is with the array-operations stacking functions. Here's an example using one of the built-in data sets:

(data 'mtcars) ; load the data frame
(tail mtcars) ; view the last few rows

;;   MODEL           MPG CYL DISP  HP DRAT    WT QSEC VS AM GEAR CARB
;; 0 Lotus Europa   30.4   4 95.1 113 3.77 1.513 16.9  1  1    5    2
;; 1 Ford Pantera L 15.8   8 351.0 264 4.22 3.170 14.5  0  1    5    4
;; 2 Ferrari Dino   19.7   6 145.0 175 3.62 2.770 15.5  0  1    5    6
;; 3 Maserati Bora  15.0   8 301.0 335 3.54 3.570 14.6  0  1    5    8
;; 4 Volvo 142E     21.4   4 121.0 109 4.11 2.780 18.6  1  1    4    2

Create a new row:

(defparameter boss-mustang #("Boss Mustang" 12.7d0 8 302 405 4.11d0 2.77d0 12.5d0 0 1 4 4)) ; a new row for the Ford Mustang

and add it using the stack-rows function:

(matrix-df
 (keys mtcars)
 (aops:stack-rows mtcars boss-mustang))
LS-USER> (tail *)

;;   MODEL           MPG CYL DISP  HP DRAT    WT QSEC VS AM GEAR CARB
;; 0 Lotus Europa   30.4   4 95.1 113 3.77 1.513 16.9  1  1    5    2
;; 1 Ford Pantera L 15.8   8 351.0 264 4.22 3.170 14.5  0  1    5    4
;; 2 Ferrari Dino   19.7   6 145.0 175 3.62 2.770 15.5  0  1    5    6
;; 3 Maserati Bora  15.0   8 301.0 335 3.54 3.570 14.6  0  1    5    8
;; 4 Volvo 142E     21.4   4 121.0 109 4.11 2.780 18.6  1  1    4    2
;; 5 Boss Mustang   12.7   8 302.0 405 4.11 2.770 12.5  0  1    4    4
NIL