Group Abstract Group Abstract

Message Boards Message Boards

0
|
17.6K Views
|
21 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How can i select a subset of information with mathematica 9?

Hello every one, i am learning how to use mathematica, i am using mathematica 9. My problem is that when i have several groups in a column i have to create several spreadsheets in order to separate the groups and be able to make operation between them.

I would like to know how to select the sub groups without creating several spreadsheets.

I add a spreadsheets and a mathematica notebook with some data in which i working on

Thank you very much.

Attachments:
POSTED BY: Oscar Rodriguez
21 Replies

Thanks Otto,

I tried the code, but for some reason is not working, i don't know if i doing something wrong.

Thank you very much

Attachments:
POSTED BY: Oscar Rodriguez

Oscar,

You probably want:

Part[Select[data, And[#[[1]] == "1 VTS",#[[7]]=="Female"] &], All, 3]

This will only give you the values in column 3 for the entries that correspond to 1 VST and females. If you also want to see the word "Female" in those entries, then you would do:

Part[Select[data, And[#[[1]] == "1 VTS",#[[7]]=="Female"] &], All, {3,7}]

You could also extract the columns 3 and 7 for both males and females (for 1 VTS) and then segregate males and females into two sublists. That would be:

GatherBy[Part[Select[data, #[[1]] == "1 VTS" &], All, {3,7}],#[[2]]&]

If after this segregation you no longer want to keep the values "Male" and "Female", then you could do:

Drop[GatherBy[Part[Select[data, #[[1]] == "1 VTS" &], All, {3,7}],#[[2]]&],None,None,2]

This is what I meant when I said you could use this to plot both datasets in the same graph (with different plot markers). The output of the command above should be a list consisting of two sublists (probably of different lengths), and each one of those is just a list of numbers. If you do a ListPlot of the output, then you should get such a plot. The x-axis will just be a counter.

Hope it helps,

OL.

POSTED BY: Otto Linsuain

Hello Otto,

I was about to say that it is great to have the option to have help in spanish...

So i try this

In[49] Part[Select[data, #[[1]] == "1 VTS" &], All, 3](Selecciona la columna 3 asociada a 1 VTS)

Out[49] {2., 1., 1., 3., 2., 3., 2., 5., 4.}

This allowed me to get the data of the column 3 associated to 1 VST. Then i tried to get the data of the column 3 associated to the sex of the participants

In[30] Part[Select[data, #[[1]] == "1 VTS" &], All, {3, 7}]

Out[30] {{2., "Female "}, {1., "Male "}, {1., "Female "}, {3., "Female "}, {2., "Female "}, {3., "Male "}, {2., "Female "}, {5., "Male "}, {4., "Female "}}

But i am no able to get the data of the column 3 associated to a specific sex, for example the data associated only to females. Could you indicate me how to do that?

POSTED BY: Oscar Rodriguez

Hello Oscar,

I think the moderators have a point in that their job is made more difficult if they do not understand the posts.

What you are trying to do only requires that you specify more parts in the command:

Part[Select[data, #[[1]] == "1 VTS" &], All, {3,n}]

where n is the column that specifies the participants' gender.

The arguments in Part (after the first one) specify the indexes you want at each depth. To specify a range of indexes, but at one given depth, you just use {} (otherwise it would be confused with a higher dimensional array and you will get an error saying that the part specification exceeds the depth of the object, or something similar). There are options for skipping entries, such as {1,-1,2} (from the first to the last skipping every other). Not sure whether one can specify entry numbers that do not follow a simple pattern (something like {{1,4,2,6,3}}). Notice that the [[]] notation and the semicolon is just a shorthand for Part, it is the same function.

Also note that the part specification is understood a bit differently in Take and Drop than it is in Part.

Best,

OL.

POSTED BY: Otto Linsuain

This forum supports currently only English language. Please use only English in your discussions so moderators and other members can understand the content.

POSTED BY: EDITORIAL BOARD
POSTED BY: Oscar Rodriguez
POSTED BY: Otto Linsuain

Hola Luis,

eres muy amable, ya he logrado individualizar vectores y hacer operaciones entre ellos (como se ve en la imagen), lo cual era mi objetivo, aún no domino muy bien la técnica pero creo que es cuestión de practicar. Muchas gracias por la guía que me has dado

Ssaludos enter image description here

POSTED BY: Oscar Rodriguez
Posted 10 years ago
POSTED BY: Luis Ledesma
POSTED BY: Oscar Rodriguez
Posted 11 years ago

Hola Oscar espero haber entendido bien tu duda, ¿quieres tener en una misma salida los elementos que tienen "1 VTS" y la tercera columna de la variable data?, de ser asi yo lo he hecho de la siguiente forma usando el archivo xlsx que has adjuntado.

data = Import[
   "C:\\Users\\miriam\\Downloads\\para wolfram comunity.xlsx", \
{"XLSX", "Data", 1}];

para despues ejecutar esto

Grid[Cases[data, {"1 VTS", _, _, _, _, _, _}]]

Obteniendo lo mismo que tu hiciste con Select, despues para lo de la tercera columna con lo de "1 VTS" hago lo siguiente que como veras es mas simple de lo que pense.

Grid[Cases[data, {"1 VTS", _, _, _, _, _, _}][[;; , 1 ;; 3 ;; 2]]]

Te comparto una imagen para que veas lo que he hecho y me digas si es lo que buscas. posible solucion

Saludos.

POSTED BY: Luis Ledesma
Attachments:
POSTED BY: Oscar Rodriguez
POSTED BY: Otto Linsuain

thank you very much, now i will work more fluently with mathematica

POSTED BY: Oscar Rodriguez
Posted 11 years ago
Attachments:
POSTED BY: David Keith

i really apreciety your help. I hope this new file be more simple

Attachments:
POSTED BY: Oscar Rodriguez
Posted 11 years ago

In your data I see some date objects in column 1, not the "1 VS" and the other things you describe. Where are these group designators? This notebook is very complicated. Is it possible you could provide a simpler example? (I will be gone tomorrow, so there will be a delay unless someone else can contribute.)

POSTED BY: David Keith

i know that it is probably an annoyance, i am learning mathematica and I can not follow you, could you please make the example directly in the mathematica notebook with my data? I will appreciate

POSTED BY: Oscar Rodriguez
Posted 11 years ago

I checked -- it was not new syntax in 10. I think it's been available for quite a while.

You can use select together with a selection condition to extract rows by content. For example, code below uses a pure function that returns True for a particular match. A row is selected if the 2nd column contains precisely "B"

In[6]:= set = {"A", "B", "C", "D"};

In[7]:= data = RandomChoice[set, {9, 5}]

Out[7]= {{"D", "D", "B", "C", "A"}, {"A", "C", "A", "A", "C"}, {"C", 
  "B", "D", "B", "C"}, {"B", "A", "A", "C", "C"}, {"B", "B", "A", "B",
   "C"}, {"B", "C", "B", "B", "C"}, {"D", "D", "B", "D", "A"}, {"D", 
  "C", "D", "C", "D"}, {"A", "A", "C", "B", "A"}}

In[8]:= Select[data, #[[2]] === "B" &]

Out[8]= {{"C", "B", "D", "B", "C"}, {"B", "B", "A", "B", "C"}}
POSTED BY: David Keith

Thanks. In this moment i only have acces to version 9. i do not know if what your code works in V9. And yes, if you see, in the column 1, for example, there are several groups (1 VS, 2 Vs, 3 VAS etc), so i need to select every rows with, for example, 3 VAS.

In this moment the only thing that i can do is create another spreadsheets in which i segregate 3 VAS, in order to make operation with other groups

POSTED BY: Oscar Rodriguez
Posted 11 years ago

Oscar,

I'm not sure I understand but if you want only a particular range of rows for a given column, it can be done like this in V10:

In[3]:= d = Table[10 j + i, {j, 9}, {i, 5}]

Out[3]= {{11, 12, 13, 14, 15}, {21, 22, 23, 24, 25}, {31, 32, 33, 34, 
  35}, {41, 42, 43, 44, 45}, {51, 52, 53, 54, 55}, {61, 62, 63, 64, 
  65}, {71, 72, 73, 74, 75}, {81, 82, 83, 84, 85}, {91, 92, 93, 94, 
  95}}

In[4]:= d[[3 ;; 5, 2]]

Out[4]= {32, 42, 52}
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard