[R] Filtering few column from one data frame based on another data frame

Rui Barradas ruipbarradas at sapo.pt
Sat Oct 13 18:10:36 CEST 2012


Hello,

Try the following.

keep <- which(!names(data2) %in% names(data1))
data1[, keep]

Hope this helps,

Rui Barradas
Em 13-10-2012 15:48, siddu479 escreveu:
> Dear R-Users and experts,
> This is my first post in this forum.
>
> I have two csv files file1 and file2.
> file1(many rows and columns) is read into dataframe *data1*
> File2 is read into dataframe *data2* which have only one column of data
> which contains the column names that need to be removed from dataframe
> *data1*columns and update the *data1 *data frame.
> Example:
> data1 <-read.csv(file1.......,header=T)
> Sno,Data_1,Data_2,Data_3
> 1,2,3,4
>
> data2<- read.csv(file2,......header=F)
> Data_2
> Data_3
>
> The output *data1.new* data frame  should be like this
>
> Sno,Data_1
> 1,2
>
> So I request the R code to accomplish this task.
>
> Regards
> Sidda
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Filtering-few-column-from-one-data-frame-based-on-another-data-frame-tp4646072.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list