examples cleaned up
[CommonLispStat.git] / examples / loading-data.lisp
blob4146b4b718ec7f4157df65a5271438266a789744
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2010-02-09 16:18:07 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: template.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
8 ;;; on how it arrives.
9 ;;; Purpose: Template header file
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
16 (in-package :cl-user)
17 (cl:defpackage :cls-examples
18 (:use :common-lisp
19 :cls-user)
20 (:export localized-pathto
21 *chkwgts-df*))
23 ;; start within the common-lisp-stat-user
24 (in-package :cls-examples)
26 ;; we'll be loading from directories in the CLS homedir, so we want to
27 ;; make it easier to reach.
28 (defun localized-pathto (x)
29 "return a string denoting the complete path.
30 FIXME: UNIX-centric (though might work on Mac OSX). Might want to
31 return a pathspec, not a string/namespec"
32 (check-type x string)
33 (concatenate 'string *cls-home-dir* x))
37 (progn
38 ;; LISP-STAT COMPATIBILITY MODE:
40 ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
41 ;; The following breaks because we should use a package to hold
42 ;; configuration details, and this would be the only package outside
43 ;; of packages.lisp, as it holds the overall defsystem structure.
44 (load-data "iris.lsp") ;; (the above partially fixed).
45 diabetes
46 (variables))
51 (progn
52 ;; COMMON LISP STATISTICS
54 ;; Importing data from DSV text files.
58 We use as an example a simple R datasert, chickwts, which has one
59 nominal categorical variable and one continuous categorical
60 variable. This dataset can be accessed in R as follows:
62 > data(chickwts)
63 > dim(chickwts)
64 [1] 71 2
65 > summary(chickwts)
66 weight feed
67 Min. :108.0 casein :12
68 1st Qu.:204.5 horsebean:10
69 Median :258.0 linseed :12
70 Mean :261.3 meatmeal :11
71 3rd Qu.:323.5 soybean :14
72 Max. :423.0 sunflower:12
76 (defparameter *chickwts-df* (filename.dsv->dataframe (localized-pathto "Data/R-chickwts.csv")))
77 ;; *chickwts-df*
78 (xref *chickwts-df* 1 1) ; => 160
79 (xref *chickwts-df* 40 2) ; => "sunflower"