1

I have a dataframe as follows where the top is the column name and each column only has one value:

     Sample122       df122      gd412     AKM     532      d21h_7
         32            4           12       25      2         55

I also have a dataframe as follows

       ID             CN
    Sample22          2
     AKM              1
     532              0

I would like to remove the columns in the dataframe based on the list I have. How can I do this?

3
  • 3
    df1[, !names(df1) %in% df2$ID ]? Commented Apr 15, 2015 at 10:03
  • 1
    Or use setdiff ie. df1[setdiff(names(df1),df2$ID)] Commented Apr 15, 2015 at 10:06
  • Thanks akrun. Can you add as an answer so I can upvote Commented Apr 15, 2015 at 17:39

1 Answer 1

2

You could try

df1[setdiff(names(df1),df2$ID)]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.