1
$\begingroup$

I'm sorry if this is obvious but I can't find a way to select only a certain amount of columns of a dataset (or delete a certain amount of columns from a dataset) using the key of each column.

I basically want to reproduce something similar to the following R code:

new_dataset <- subset(initial_dataset, select = c("key1", "key5", "key7"))

which then returns only columns 1, 5 and 7 using the name of the column (for the sake of this example simply named "key1", "key5", and "key7"

$\endgroup$

closed as off-topic by m_goldberg, Karsten 7., Sjoerd C. de Vries, ubpdqn, Mr.Wizard Jan 31 '15 at 5:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, Karsten 7., Sjoerd C. de Vries, ubpdqn, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ I think you can simply select certain columns from the whole matrix m. Something like this: m2=m[[1;;3,All]]. $\endgroup$ – Chen Stats Yu Jan 30 '15 at 1:17
  • $\begingroup$ @ChenStatsYu If m is a matrix that would be m[[All,1;;3]]. You're selecting rows instead of columns. $\endgroup$ – Sjoerd C. de Vries Jan 30 '15 at 7:41
  • $\begingroup$ I meant the data structure Dataset. It's all good now, with KeyDrop[] it works fine. However, overall I'm still not convinced of how Mathematica handles those Dataset structures, for example, at least in version 10.0.1.0 it seems impossible to change the value of an element of a data set. I also have no idea how to create a Dataset from the columns rather than rows. (so let's say we have 5 vectors, and want those 5 vectors to be the columns of a dataset). $\endgroup$ – Moppentapper Jan 30 '15 at 12:54
  • $\begingroup$ @SjoerdC.deVries Yes, you are right. I was only thinking about an example, did not pay too much to the details. $\endgroup$ – Chen Stats Yu Jan 30 '15 at 14:41
6
$\begingroup$

Check out of the documentation for Dataset, it's easy: enter image description here

$\endgroup$
  • 1
    $\begingroup$ Yeah sorry about that I should have had a better read of the documentation. I was more trying to figure out how to drop a specific column using the keys as well. Is it possible to just Delete or Drop a single column of a data set using the Key name? $\endgroup$ – Moppentapper Jan 30 '15 at 1:31
  • 1
    $\begingroup$ reference.wolfram.com/language/ref/KeyDrop.html $\endgroup$ – alancalvitti Jan 30 '15 at 1:42
  • $\begingroup$ Brilliant thanks! $\endgroup$ – Moppentapper Jan 30 '15 at 2:15
  • $\begingroup$ On a related matter, is that possible to name both the rows and column? See i.stack.imgur.com/okt9w.png for example. I read the doc, it looks like that the Dataset only takes "column"? In my example, I want to be able to extract rows as well, say dataset["B1997"] as well as dataset["Bin"]. Is that possible? $\endgroup$ – Chen Stats Yu Jan 30 '15 at 14:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.