# How to subset datasets in Mathematica 10 [closed]

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"

• I think you can simply select certain columns from the whole matrix m. Something like this: m2=m[[1;;3,All]]. – Chen Stats Yu Jan 30 '15 at 1:17
• @ChenStatsYu If m is a matrix that would be m[[All,1;;3]]. You're selecting rows instead of columns. – Sjoerd C. de Vries Jan 30 '15 at 7:41
• 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). – Moppentapper Jan 30 '15 at 12:54
• @SjoerdC.deVries Yes, you are right. I was only thinking about an example, did not pay too much to the details. – Chen Stats Yu Jan 30 '15 at 14:41

Check out of the documentation for Dataset, it's easy: • 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? – Chen Stats Yu Jan 30 '15 at 14:49