Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11154 > unrolled thread

Data Format

Started by"Nicholas Kormanik" <nkormanik@gmail.com>
First post2012-08-01 09:02 +0000
Last post2012-08-02 08:52 +0000
Articles 5 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Data Format "Nicholas Kormanik" <nkormanik@gmail.com> - 2012-08-01 09:02 +0000
    Re: Data Format awnl <awnl@gmx-topmail.de> - 2012-08-02 08:46 +0000
      Re: Data Format Ray Koopman <koopman@sfu.ca> - 2012-08-03 08:18 +0000
        Re: Data Format awnl <awnl@gmx-topmail.de> - 2012-08-04 10:04 +0000
    Re: Data Format Murta <rodrigomurtax@gmail.com> - 2012-08-02 08:52 +0000

#11154 — Data Format

From"Nicholas Kormanik" <nkormanik@gmail.com>
Date2012-08-01 09:02 +0000
SubjectData Format
Message-ID<jvaran$751$1@smc.vnet.net>
Please consider the following code, which is data imported directly into
Mathematica via a .mtp file (Minitab Portable Worksheet), and then using
list assignment:

    list = {"C1" -> {5.`, 4.`, 7.`, 3.`, 6.`, 6.`, 7.`, 1.`, 5.`, 6.`}, "C2"
-> {2.`, 5.`, 6.`, 7.`, 7.`, 1.`, 5.`, 4.`, 7.`, 2.`}}

The following two commands work:

    Mean["C1" /. list]

    Mean["C2" /. list]

However I would prefer to be able to issue the following commands instead:

    Mean[C1]

    Mean[C2]

How can the code at top be converted so that these simpler commands will
work?

Thanks.

Nicholas Kormanik



[toc] | [next] | [standalone]


#11159

Fromawnl <awnl@gmx-topmail.de>
Date2012-08-02 08:46 +0000
Message-ID<jvdepb$bvi$1@smc.vnet.net>
In reply to#11154
Hi,

> Please consider the following code, which is data imported directly into
> Mathematica via a .mtp file (Minitab Portable Worksheet), and then using
> list assignment:
>
>      list = {"C1" -> {5.`, 4.`, 7.`, 3.`, 6.`, 6.`, 7.`, 1.`, 5.`, 6.`}, "C2"
> -> {2.`, 5.`, 6.`, 7.`, 7.`, 1.`, 5.`, 4.`, 7.`, 2.`}}
>
> The following two commands work:
>
>      Mean["C1" /. list]
>
>      Mean["C2" /. list]
>
> However I would prefer to be able to issue the following commands instead:
>
>      Mean[C1]
>
>      Mean[C2]
>
> How can the code at top be converted so that these simpler commands will
> work?

For just this simple case I wouldn't suggest to create the symbols C1 
and C2. For more complicated cases it might be a reasonable choice but 
probably there are better ways to deal with this. Anyway, this will do 
what I think you want:

(Set @@ {Symbol[#1], #2}) & @@@ list

it will define the symbols C1 and C2 and set their values to the 
corresponding lists. @@ and @@@ are shortcuts for Apply.

hth

Albert

[toc] | [prev] | [next] | [standalone]


#11186

FromRay Koopman <koopman@sfu.ca>
Date2012-08-03 08:18 +0000
Message-ID<jvg1h9$rk9$1@smc.vnet.net>
In reply to#11159
On Aug 2, 1:46 am, awnl <a...@gmx-topmail.de> wrote:
>> Hi,
>> Please consider the following code, which is data imported directly into
>> Mathematica via a .mtp file (Minitab Portable Worksheet), and then using
>> list assignment:
>>
>>      list = {"C1" -> {5.`, 4.`, 7.`, 3.`, 6.`, 6.`, 7.`, 1.`, 5.`, 6.`},
>>              "C2" -> {2.`, 5.`, 6.`, 7.`, 7.`, 1.`, 5.`, 4.`, 7.`, 2.`}}
>>
>> The following two commands work:
>>
>>      Mean["C1" /. list]
>>
>>      Mean["C2" /. list]
>>
>> However I would prefer to be able to issue the following commands instead:
>>
>>      Mean[C1]
>>
>>      Mean[C2]
>>
>> How can the code at top be converted so that these simpler commands will
>> work?
>
> For just this simple case I wouldn't suggest to create the symbols C1
> and C2. For more complicated cases it might be a reasonable choice but
> probably there are better ways to deal with this. Anyway, this will do
> what I think you want:
>
> (Set @@ {Symbol[#1], #2}) & @@@ list

You might want to precede that by

  Clear @@ (First /@ list)

just in case the symbols in 'list' are already defined.

>
> it will define the symbols C1 and C2 and set their values to the
> corresponding lists. @@ and @@@ are shortcuts for Apply.
>
> hth
>
> Albert

[toc] | [prev] | [next] | [standalone]


#11200

Fromawnl <awnl@gmx-topmail.de>
Date2012-08-04 10:04 +0000
Message-ID<jvis2t$2ud$1@smc.vnet.net>
In reply to#11186
Hi,

>>> Please consider the following code, which is data imported directly into
>>> Mathematica via a .mtp file (Minitab Portable Worksheet), and then using
>>> list assignment:
>>>
>>>       list = {"C1" -> {5.`, 4.`, 7.`, 3.`, 6.`, 6.`, 7.`, 1.`, 5.`, 6.`},
>>>               "C2" -> {2.`, 5.`, 6.`, 7.`, 7.`, 1.`, 5.`, 4.`, 7.`, 2.`}}
>>>
>>> The following two commands work:
>>>
>>>       Mean["C1" /. list]
>>>
>>>       Mean["C2" /. list]
>>>
>>> However I would prefer to be able to issue the following commands instead:
>>>
>>>       Mean[C1]
>>>
>>>       Mean[C2]
>>>
>>> How can the code at top be converted so that these simpler commands will
>>> work?
>>
>> For just this simple case I wouldn't suggest to create the symbols C1
>> and C2. For more complicated cases it might be a reasonable choice but
>> probably there are better ways to deal with this. Anyway, this will do
>> what I think you want:
>>
>> (Set @@ {Symbol[#1], #2}) & @@@ list
>
> You might want to precede that by
>
>    Clear @@ (First /@ list)
>
> just in case the symbols in 'list' are already defined.

very good point, alternatively you could use the following code, which 
takes care to not evaluate the symbols it assigns to:

(Set @@ Append[ToExpression[#1,InputForm,Hold],#2]) & @@@ list

albert

[toc] | [prev] | [next] | [standalone]


#11168

FromMurta <rodrigomurtax@gmail.com>
Date2012-08-02 08:52 +0000
Message-ID<jvdf3g$c36$1@smc.vnet.net>
In reply to#11154
Hi Nicholas, you could try this:

list={"C1"->{5.`,4.`,7.`,3.`,6.`,6.`,7.`,1.`,5.`,6.`},"C2"->{2.`,5.`,6.`,7.`,7.`,1.`,5.`,4.`,7.`,2.`}};

createSymbolsFromList[list_]:=Module[{varList},              
	Clear @@ list[[All,1]] // Quiet;
	(Evaluate[Symbol[#[[1]]]] = #[[2]])&/@list;
]
createSymbolsFromList[list]
{Mean[C1],Mean[C2]}
---------
output {5.,4.6}

Best Regards
Murta

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web