Home > Software engineering >  extracting specific column with certain condition on one column only
extracting specific column with certain condition on one column only

Time:10-12

I have a data(in R) in below form,

enter image description here

A B C D x alpha sine 0 y gama cos 1 z beta tan 2

and I want to extract only column A & B where column D > 0. i tried using data %>% filter(D > 0), which gives me last two rows where D>0 but it also gives me column c which i don't want. how can i get only column A&B with condition applied on column D only.?

Data in text:

A B C D
x alpha sine 0
y gama cos 1
z beta tan 2

CodePudding user response:

data %>% filter(D > 0) %>%select(A,B, D)
  A    B D
1 y gama 1
2 z beta 2

or even:

data %>% filter(D > 0) %>%select(-C)
  A    B D
1 y gama 1
2 z beta 2
  •  Tags:  
  • r
  • Related