This might be an easy question but i still need some help for using R.
I have a data.frame (main_data), lets say..
NAMES   AGE     LOC Jyo     23      Hyd Abid    27      Kar Ras     24      Pun Poo     25      Goa Sus     28      Kar   I wish to remove a few rows based on a list of names. So lets say I have another list of table as follows:
NAMES_list Jyo Ras Poo   So based on this list, if any of the names match to my above "main_data" table, then I would like to remove the whole row contianing them, so the result should be as follows
NAMES   AGE     LOC Abid    27      Kar Sus     28      Kar   Can anyone help me how to achive this using R? Thanks in advance.. :)
For example, we can use the subset() function if we want to drop a row based on a condition. If we prefer to work with the Tidyverse package, we can use the filter() function to remove (or select) rows based on values in a column (conditionally, that is, and the same as using subset).
To remove the rows in R, use the subsetting in R. There is no built-in function of removing a row from the data frame, but you can access a data frame without some rows specified by the negative index. This process is also called subsetting. This way, you can remove unwanted rows from the data frame.
To remove rows of data from a dataframe based on multiple conditional statements. We use square brackets [ ] with the dataframe and put multiple conditional statements along with AND or OR operator inside it. This slices the dataframe and removes all the rows that do not satisfy the given conditions.
Use %in%:
main_data2 <- main_data[ ! main_data$NAMES %in% NAMES_list, ] 
                        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