How can I subset rows in a data frame in R based on a vector of values?

前端 未结 4 1890
挽巷
挽巷 2020-11-28 04:48

I have two data sets that are supposed to be the same size but aren\'t. I need to trim the values from A that are not in B and vice versa in order to eliminate noise from a

4条回答
  •  旧时难觅i
    2020-11-28 05:03

    This will give you what you want:

    eg2011cleaned <- eg2011[!eg2011$ID %in% bg2011missingFromBeg, ]
    

    The error in your second attempt is because you forgot the ,

    In general, for convenience, the specification object[index] subsets columns for a 2d object. If you want to subset rows and keep all columns you have to use the specification object[index_rows, index_columns], while index_cols can be left blank, which will use all columns by default.

    However, you still need to include the , to indicate that you want to get a subset of rows instead of a subset of columns.

提交回复
热议问题