How to subset rows from a data frame with comparison operators in R I have a data frame (a csv file) with dimensions 100x6 and I need only the columns c("X1", "X2", "X4") and the rows in which the value of "X1" is greater than 30. So I did:

  data_frame &lt;- read.csv ("data_frame")
  data_frame [c("X1", "X2", "X4")]


The column subset problem is solved but now I need to subset rows from data_frame [c("X1", "X2", "X4")] where the values of "X1" is greater than 30. I tried:

  data_frame [c("X1" &gt; 30), c("X1", "X2", "X4")] 


But it returned the same data frame as data_frame [c("X1", "X2", "X4")].
Also tried using the function subset() with the same approach but got the same results.
You want

data_frame[data_frame$X1 &gt; 30, c("X1","X2","X4")]


that will just print it, you probably want to update data_frame or store it in something else:

data_frame = data_frame[data_frame$X1 &gt; 30, c("X1","X2","X4")]


also you probably want to try asking this on StackOverflow, or reading a bit more basic R documentation because it should be well covered. Its a bit simple to be "data science".