MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Is there a similar data structure to Splus' dataframe?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23101] Re: [mg23071] Is there a similar data structure to Splus' dataframe?
  • From: BobHanlon at aol.com
  • Date: Sun, 16 Apr 2000 00:37:39 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Starting with a  matrix

m = Array[f, {3, 4}];

Define names for columns

{a, b, c, d} = m[[All, #]] & /@ Range[4];

Verify assignment


m == Transpose[{a, b, c, d}]
True

Refer to a column

a

{f[1, 1], f[2, 1], f[3, 1]}

If you want to share common names between different matrices then use 
something like this

matrixColumn[matrix_, columnName_] :=  
  Module[{colNames = {"a", "b", "c", "d"}}, 
    matrix[[All, Position[colNames, columnName][[1, 1]]]]]

matrixColumn[m, "a"]

{f[1, 1], f[2, 1], f[3, 1]}

{a, b, c, d} == (matrixColumn[m, #] & /@ {"a", "b", "c", "d"})

True

Bob Hanlon

In a message dated 4/15/2000 3:29:30 AM, schnoerr at mailzone.com writes:

>I would like to give columns of matrices names which I can use to
>select these columns.
>
>In Splus there is a fine syntax for that: matrix[,"name"] selects a
>column whithout having to know its position in the matrix (2nd or 3rd
>column for example).
>
>Is there a predefined data structure and commands  or a package to do
>that whithout the need to program it for myself with the Select[]
>statement?
>


  • Prev by Date: Keyboard shortcuts do not work
  • Next by Date: Re: Directory Function
  • Previous by thread: Is there a similar data structure to Splus' dataframe?
  • Next by thread: Re: Is there a similar data structure to Splus' dataframe?