Subsetting rows with range of column having same values

Newbie

In R with a dataframe:

     one two three four
  1   A   A    Z   Z
  2   A   A    A   Z
  3   A   A    A   A
  4   Z   A    A   A
  5   A   A    A   A

I want to extract the subset whose rows have at least one Z in column two : four. That is:

         one two three four
      1   A   A    Z   Z
      2   A   A    A   Z
akrun

We can use rowSums on a logical matrix (from removing the first column (df[-1] and comparing (==) with "Z") to extract the rows

df1[rowSums(df1[-1]=="Z")>0,]
#  one two three four
#1   A   A     Z    Z
#2   A   A     A    Z

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

PostgreSQL select rows having same column values

From Dev

find a continuous range of rows with the same column values

From Dev

find a continuous range of rows with the same column values

From Dev

Total Values of Rows having same value in specific column

From Dev

MySQL Select the rows having same column value

From Dev

Linux: Merging rows by the columns having same values

From Dev

Merge rows having same values in multiple columns

From Dev

Linux: Merging rows by the columns having same values

From Dev

SQL find rows not having duplicate column values

From Dev

Copy values of a row in to column having same key

From Dev

Subsetting list by values in a column in r

From Dev

Subsetting a CSV by unique column values

From Dev

Delete rows based on range of values in column

From Dev

How to check between range of values of same column

From Dev

Select rows having same column value more than 3 times

From Dev

select rows in mysql having another column with same value

From Dev

Combine multiple rows to single row having same values

From Dev

MySQL - Select multiple rows with the same values with one having to be different

From Dev

Get rows with matching values in column in same table

From Dev

Select rows with same column values (Mysql)

From Dev

merge 2 rows based on the same column values

From Dev

Excel: how to sort rows by same column values

From Dev

fetch rows data with same values in two column

From Dev

Missing rows after subsetting datatable on a single column

From Dev

R - interactive subsetting of rows by vector of column headers

From Dev

How to find rows with column values having a particular datatype in a Pandas DATAFRAME

From Dev

Display different rows of a record in a single row having all the column values

From Dev

Counting the number of rows of having one column values are matching

From Dev

How To Join Two Tables Having Some Values Same in the Column

Related Related

  1. 1

    PostgreSQL select rows having same column values

  2. 2

    find a continuous range of rows with the same column values

  3. 3

    find a continuous range of rows with the same column values

  4. 4

    Total Values of Rows having same value in specific column

  5. 5

    MySQL Select the rows having same column value

  6. 6

    Linux: Merging rows by the columns having same values

  7. 7

    Merge rows having same values in multiple columns

  8. 8

    Linux: Merging rows by the columns having same values

  9. 9

    SQL find rows not having duplicate column values

  10. 10

    Copy values of a row in to column having same key

  11. 11

    Subsetting list by values in a column in r

  12. 12

    Subsetting a CSV by unique column values

  13. 13

    Delete rows based on range of values in column

  14. 14

    How to check between range of values of same column

  15. 15

    Select rows having same column value more than 3 times

  16. 16

    select rows in mysql having another column with same value

  17. 17

    Combine multiple rows to single row having same values

  18. 18

    MySQL - Select multiple rows with the same values with one having to be different

  19. 19

    Get rows with matching values in column in same table

  20. 20

    Select rows with same column values (Mysql)

  21. 21

    merge 2 rows based on the same column values

  22. 22

    Excel: how to sort rows by same column values

  23. 23

    fetch rows data with same values in two column

  24. 24

    Missing rows after subsetting datatable on a single column

  25. 25

    R - interactive subsetting of rows by vector of column headers

  26. 26

    How to find rows with column values having a particular datatype in a Pandas DATAFRAME

  27. 27

    Display different rows of a record in a single row having all the column values

  28. 28

    Counting the number of rows of having one column values are matching

  29. 29

    How To Join Two Tables Having Some Values Same in the Column

HotTag

Archive