Is there a special Mathematica way of joining tables of data together, so that I would get similar functionality as if I was running a database with sql?
For example, I have one particular table here, and getting data out of it is getting a bit verbose. Here is an example, but is there a better way to work with data. I thought there would be a simple way of creating tables and joining them, something similar to a dataframe in R perhaps?
Tally[
Flatten[
GatherBy[Transpose[{data[[All, 9]], data[[All, 8]]}], # == "Yes"] ,
1
]
]
returns
(*
{
{{"Yes", "South West"}, 42}, {{"No", "The North"}, 325},
{{"Yes", "Midlands & East Anglia"}, 92}, {{"No", "Scotland"}, 97},
{{"No", "Midlands & East Anglia"}, 351}, {{"Yes", "Wales"}, 20},
{{"No", "South East"}, 187}, {{"No", "South West"}, 115},
{{"No", "Wales"}, 63}, {{"No", "London"}, 132}, {{"Yes", "London"}, 50},
{{"Yes", "The North"}, 101}, {{"Yes", "South East"}, 65},
{{"Yes", "Scotland"}, 51}
}
*)
Here is an example of the data I am working with:
{{"gender", "age", "maritalStatus", "highestQualification", "nationality", "ethnicity",
"grossIncome", "region", "smoke", "amtWeekends", "amtWeekdays", "type"},
{"Female", 51, "Divorced", "Other/Sub Degree", "English", "White",
"Unknown", "South West", "Yes", 25, 25, "Packets"},
{"Female", 52, "Married", "No Qualification", "English", "White",
"Unknown", "The North", "No", "NA", "NA", ""},
{"Female", 53, "Divorced", "GCSE/O Level", "English", "White",
"Unknown", "Midlands & East Anglia", "Yes", 7, 12, "Packets"},
{"Female", 59, "Divorced", "Degree", "Scottish", "White",
"Unknown", "Scotland", "No", "NA", "NA", ""},
{"Female", 61, "Married", "A Levels", "English", "White",
"Unknown", "Midlands & East Anglia", "No", "NA", "NA", ""},
{"Male", 66, "Married", "No Qualification", "English", "White",
"Unknown", "The North", "No", "NA", "NA", ""},
{"Female", 69, "Widowed", "No Qualification", "English", "White",
"Unknown", "Wales", "Yes", 15, 15, "Packets"},
{"Female", 69, "Widowed", "No Qualification", "English", "White",
"Unknown", "The North", "No", "NA", "NA", ""},
{"Male", 71, "Divorced", "No Qualification", "English", "White",
"Unknown", "The North", "No", "NA", "NA", ""}}
data
? $\endgroup$ – Leonid Shifrin May 10 '14 at 16:18# == "Yes"
, while a pure function should end with an ampersand :# == "Yes"&
. $\endgroup$ – Leonid Shifrin May 10 '14 at 16:23