I currently started to work with octave for some data analysis and have some problems for a specific matrix manipulation.
Assume you have the following data matrix:
A = 1 11 22 33 44 13 12 33 1 14 33 44
Now I would like to delete all rows of this matrix which don't accomplish e.g. the following condition.
octave:6> A(:, 4) == 33 ans = 1 1 0
And I'll get the matrix of this form which only selects these rows:
A_new = 1 11 22 33 44 13 12 33
I know this is possible with the help of some loops. But is there maybe a cleaner solution e.g. by using the provided standard library? That would be great :]
Some similar question was also already posted for R: In R, select rows of a matrix that meet a condition
Using count() method in Python Pandas we can count the rows and columns. Count method requires axis information, axis=1 for column and axis=0 for row. To count the rows in Python Pandas type df. count(axis=1) , where df is the dataframe and axis=1 refers to column.
By using bracket notation on R DataFrame (data.name) we can select rows by column value, by index, by name, by condition e.t.c. You can also use the R base function subset() to get the same results. Besides these, R also provides another function dplyr::filter() to get the rows from the DataFrame.
Try:
A = [ 1 11 22 33 44 13 12 33 1 14 33 44 ]; idx = ( A(:,4)==33 ); A_new = A(idx,:)
This is using logical indexing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With