Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extend a frame by adding columns. Append two frames by appending comm…

…on columns.
  • Loading branch information...
commit 6cb7fab6d041f939618d2a9cb671a44d43e0533e 1 parent caa41b4
@RayRacine authored
Showing with 60 additions and 3 deletions.
  1. +39 −0 rpr/frame/frame-join.rkt
  2. +21 −3 rpr/frame/frame.rkt
View
39 rpr/frame/frame-join.rkt
@@ -1,6 +1,25 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Ray Racine's Data Munger Library
+;; Copyright (C) 2007-2013 Raymond Paul Racine
+;;
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
#lang typed/racket/base
(provide:
+ [frame-append (Frame Frame [#:col (Listof Symbol)] -> Frame)]
[frame-merge (Frame Frame [#:on (Listof Symbol)] -> Frame)])
(require
@@ -41,6 +60,8 @@
CSeriesBuilder CSeriesBuilder?
append-CSeriesBuilder complete-CSeriesBuilder
new-CSeriesBuilder)
+ (only-in "categorical-series-ops.rkt"
+ cseries-append)
(only-in "numeric-series-builder.rkt"
NSeriesBuilder NSeriesBuilder?
append-NSeriesBuilder complete-NSeriesBuilder
@@ -242,3 +263,21 @@
(series-complete builder))))
(new-frame (append new-a-series new-b-series)))
+
+
+;; Append common columns
+(: frame-append (Frame Frame [#:col (Listof Symbol)] -> Frame))
+(define (frame-append fa fb #:cols [cols '()])
+
+ (define: cols-a : (Setof Label) (list->set (frame-names fa)))
+ (define: cols-b : (Setof Label) (list->set (frame-names fb)))
+ (define: append-cols : (Setof Label) (if (null? cols)
+ (set-intersect cols-a cols-b)
+ (set-intersect (list->set cols)
+ (set-intersect cols-a cols-b))))
+ (new-frame (map (λ: ((name : Label))
+ (cons name (cseries-append (frame-cseries fa name)
+ (frame-cseries fb name))))
+ (filter (λ: ((name : Label))
+ (set-member? append-cols name))
+ (frame-names fa)))))
View
24 rpr/frame/frame.rkt
@@ -1,3 +1,21 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Ray Racine's Data Munger Library
+;; Copyright (C) 2007-2013 Raymond Paul Racine
+;;
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
#lang typed/racket/base
(provide:
@@ -6,7 +24,7 @@
[frame-rename (Frame Label Label -> Frame)]
[frame-drop (Frame Label -> Frame)]
[frame-explode (Frame [#:project LabelProjection] -> Columns)]
- [frame-append (Frame (U Column Columns Frame) -> Frame)]
+ [frame-extend (Frame (U Column Columns Frame) -> Frame)]
[frame-description (Frame [#:project LabelProjection] -> FrameDescription)]
[show-frame-description (FrameDescription -> Void)])
@@ -212,8 +230,8 @@
(car l-s))
project)))
-(: frame-append (Frame (U Column Columns Frame) -> Frame))
-(define (frame-append frame cols)
+(: frame-extend (Frame (U Column Columns Frame) -> Frame))
+(define (frame-extend frame cols)
(cond
((Frame? cols)
(new-frame (append (frame-explode frame) (frame-explode cols))))
Please sign in to comment.
Something went wrong with that request. Please try again.