Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206305

Selecting non-consecutive columns in R tables

$
0
0

Let's say I have a some table, T. Assume T has 5 columns. I understand how to select any consecutive subset of columns and store them as a new table. For that I would use brackets and a colon to the right of a comma:

newT <- T[,2:4]   # creates newT from columns 2 through 4 in T

But how do I select non-consecutive columns for subsetting? Let's say I want to select Column 1 and Column 3? How do I go about doing this? Another type of selection I may want to do, and not sure how to, is selecting random columns from T.


Viewing all articles
Browse latest Browse all 206305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>