subset

Hi,

I have a dataset

A            B            C

5.450     26.950      1.000

4.850     26.030      0.000

2.650     21.960      0.000

2.720     22.310      0.000

I would like to subset data for values C=1 as shown below:

A            B            C

3.520     24.270      1.000

3.730     24.720      1.000

4.650     25.930      1.000

Could you please let me know how to do this?

Have a nice time

1 Answer



0



You can use the selif command to "select" some rows of the data "if" they meet some condition.

selif takes two inputs:

  1. The data from which the subset should be selected.
  2. A vector of 1's and 0's indicating which rows should be selected.

Since your third column is already a vector with 1's for the rows we want to select, you can just do this:

X =  { 3.52   24.27   1,
       3.73   24.72   1,
       4.65   25.93   1,
       5.45   26.95   1,
       4.85   26.03   0,    
       2.65   21.96   0,
       2.72   22.31   0 };

// Select rows where the element
// in the third row is non-zero
X_subset = selif(X, X[.,3]);

print X_subset;

which will print out:

  3.520  24.270   1.000
  3.730  24.720   1.000
  4.650  25.930   1.000
  5.450  26.950   1.000

aptech

1,773

Your Answer

1 Answer

0

You can use the selif command to "select" some rows of the data "if" they meet some condition.

selif takes two inputs:

  1. The data from which the subset should be selected.
  2. A vector of 1's and 0's indicating which rows should be selected.

Since your third column is already a vector with 1's for the rows we want to select, you can just do this:

X =  { 3.52   24.27   1,
       3.73   24.72   1,
       4.65   25.93   1,
       5.45   26.95   1,
       4.85   26.03   0,    
       2.65   21.96   0,
       2.72   22.31   0 };

// Select rows where the element
// in the third row is non-zero
X_subset = selif(X, X[.,3]);

print X_subset;

which will print out:

  3.520  24.270   1.000
  3.730  24.720   1.000
  4.650  25.930   1.000
  5.450  26.950   1.000


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy