Message Boards Message Boards

0
|
11063 Views
|
13 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to use Drop with this data?

hi every one,

i'm trying to use drop to select different set of information, but i don't know if there is the best way to do it. I want to select what is mark with the red arrows, i mean, only the second column and the rows that correspond to females.

I will appreciate any help This the first thing that i did

An this the information the i am trying to select

POSTED BY: Oscar Rodriguez
13 Replies
Posted 9 years ago

Just what I was doing! The attached file uses a select similar to Marco's. You will find it in the last section.

Attachments:
POSTED BY: David Keith

Hello David,

I appreciate your help, now i'm going to replicate the code with my data.

Thank you very much

POSTED BY: Oscar Rodriguez

What about

Part[Select[data, (#[[1]] == "1 VTS" && StringContainsQ[#[[7]], "Female"]) &], All]

Cheers,

Marco

POSTED BY: Marco Thiel
Posted 9 years ago

Thanks Marco,

Unfortunately StringContainsQ is only available in Mathe 10, but i only have acces to version 9

Thank you

POSTED BY: Updating Name

Hi Oscar,

the StringContainsQ is only there because the search string contains spaces etc. If you take the exact search string and "double equal" it to #[[7]] it should work, too. If you had MMA10 the StringContainsQ function is slightly better, becaus it gives the result you want and also caters for cases where spaces etc are not always entered in the same way.

Cheers, Matco

POSTED BY: Marco Thiel

Hello Marco,

Thank you very much for your help and your explanations, i going to try to aplly the code to my data

greetings

POSTED BY: Oscar Rodriguez
Posted 9 years ago

Select can be used outside of query, and was available much earlier.

In[1]:= Vts = {{"1 VTS", 2., 2., 5., 2., 5., "Female"}, {"1 VTS", 2., 
    2., 5., 2., 5., "Male"}, {"1 VTS", 2., 2., 5., 2., 5., "Female"}};

In[2]:= Select[Vts, #[[7]] == "Female" &]

Out[2]= {{"1 VTS", 2., 2., 5., 2., 5., "Female"}, {"1 VTS", 2., 2., 
  5., 2., 5., "Female"}}

In[3]:= (* Note:  #[[7]]\[Equal]"Female"& is a "pure function" *)
POSTED BY: David Keith

Hello David,

Thanks for the advice. But what i am trying to do is select only one column or any column that is associated to two variables, in this case what i want to do is, for example, select the information in the second column that is associated to a specific gender (male or female) and to the variable 1 VTS (first column). For now i know how to select information that is associated to the variables in the first column, to do that i use Part[Select[data, #[[1]] == "1 VTS" &], All, 3], but i do not know how to do it with the gender.

It will be of great help if you can gave me an example directly in mathematica note book.

Thank you

Attachments:
POSTED BY: Oscar Rodriguez

Query makes this sort of task easy.

Vts = {{"1 VTS", 2., 2., 5., 2., 5., "Female"},
   {"1 VTS", 2., 2., 5., 2., 5., "Male"},
   {"1 VTS", 2., 2., 5., 2., 5., "Female"}};
Query[Select[#[[7]] == "Female" &], 2]@Vts

A slight modification will give the total.

Query[Select[#[[7]] == "Female" &] /* Total, 2]@Vts
POSTED BY: Emerson Willard

Hello Emmerson,

I tried what you show me, but i did not work, then i realise that Query is an option only in mathematica 10 and for now i have access to mathematica 9. There is a similar option in mathematica 9?

I'll add the excel file and the notebook, probably it will help

Thank you

Attachments:
POSTED BY: Oscar Rodriguez
Posted 9 years ago

deleted..

POSTED BY: Okkes Dulgerci
Posted 9 years ago
Vts = {{2, 1, 3, f}, {7, 1, 4, m}, {1, 4, 8, f}, {3, 4, 7, f}};
v = Select[Vts, MemberQ[#, f] &]
{{2, 1, 3, f}, {1, 4, 8, f}, {3, 4, 7, f}}
v[[All, 2]]
{1, 4, 4}

Replace f by Female

POSTED BY: Okkes Dulgerci

Hello Okkes,

I was trying the code but i did not work, i think that i am doing something wrong (i am learning). I would like to add the notebook and the excel file, probably i'll understand better with the code in the notebook

Thank you

Attachments:
POSTED BY: Oscar Rodriguez
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract