# Subset two non-consective columns of a Matrix

**URL:** <https://discourse.mc-stan.org/t/subset-two-non-consective-columns-of-a-matrix/20518>\
**Category:** Modeling\
**Created:** [January 29, 2021, 8:52pm UTC](https://discourse.mc-stan.org/t/subset-two-non-consective-columns-of-a-matrix/20518 "2021-01-29T20:52:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balexanderstats](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@Balexanderstats](https://discourse.mc-stan.org/u/Balexanderstats)\
**Post date:** [January 29, 2021, 8:52pm UTC](https://discourse.mc-stan.org/t/subset-two-non-consective-columns-of-a-matrix/20518/1 "2021-01-29T20:52:05Z")

</div>

I have a nx7 matrix in stan. I need to access the 1st and 7th column if a condition is met, but access the 2nd-7th columns under another condition. I am basically running a regression model like a seemingly unrelated regression but some of the terms are irrelevant for the sub regressions. In R I would do this with mat[,c(1,7)] but how would I do that in stan?

* * *

```stan
data {
  matrix[m,n] M; 
} 

```

---

<div class="post-metadata">

**Author:** ![Stephen\_Martin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stephen_martin/32/7879_2.png) [@Stephen\_Martin](https://discourse.mc-stan.org/u/Stephen_Martin)\
**Post date:** [January 30, 2021, 8:23am UTC](https://discourse.mc-stan.org/t/subset-two-non-consective-columns-of-a-matrix/20518/2 "2021-01-30T08:23:14Z")

</div>

> **[6.3 Vector, matrix, and array expressions | Stan Reference Manual](https://mc-stan.org/docs/2_26/reference-manual/vector-matrix-array-expressions-section.html)**
>
> Stan reference manual specifying the syntax and semantics of the Stan programming language.

Could you use M[{1, 7}] ? Iirc, you can’t, but I couldn’t find it in the docs in my cursory glance.

If not, then in transformed data, just add

```
int my_subset[2] = {1,7};

```

Then later:

```
... M[my_subset] ...

```
