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"

  • $\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 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

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

|improve this answer|||||
  • 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.