51083

How can I compare two csv file in R?

Question:

I have two csv file, A and B.

I want to find the number of different column between A and B.

For example, let's assume that A contains 7, 9, 0, 0, 2 and B contains 7,8,6,0,2 ( so A and B have five column each). Then, the number of different column is 2, the second and third column.

How can I implement this on R?

Answer1:

You could try

indx <- colSums(A!=B) which(!!indx) #gets the index of different columns # Col2 Col3 # 2 3 which(!indx) #gets the index of similar columns #Col1 Col4 Col5 # 1 4 5 length(which(!indx) ) #[1] 3 <h3>data</h3> A <- data.frame(Col1= c(7,2), Col2= c(9,4), Col3= c(0,5), Col4= c(0,3), Col5=c(2,3)) B <- data.frame(Col1= c(7,2), Col2= c(8,4), Col3= c(6,5), Col4= c(0,3), Col5=c(2,3))

Recommend

  • Changing the background image based on the day of the week
  • Avoiding 'sort order by' in query plan
  • Adding columns sums in dataframe row wise
  • Shiny App-showModal does not pop up with renderSankeyNetwork
  • How to remove empty columns in R?
  • Removing negative values when variable is an atomic vector
  • Row and column sums in R
  • F# slicing array by indices array
  • How to remove comma or any characters from Python dataframe column name
  • SSH in Bash Script Messing Up File Read
  • What's the syntax to inherit documentation from another indexer?
  • Drawing a Path in XAML (with binding) vs. C#. One works, one doesn't
  • Hash Code in SQL Server?
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • jQuery: add elements until a particular height is reached
  • Combining two different ActiveRecord collections into one
  • Ember.js model to be organised as a tree structure
  • Django simple Captcha “No module named fields” error
  • Groovy: Unexpected token “:”
  • Textfile Structure (tables)
  • How to use carriage return with multiple line?
  • Replace value with Factor in r data.table
  • How to access EntityManager inside Entity class in EJB3
  • Repeat a vertical line on every page in Report Builder / SSRS
  • C# - Serializing and deserializing static member
  • Bug in WPF DataGrid
  • Incrementing object id automatically JS constructor (static method and variable)
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Can't mass-assign protected attributes when import data from csv file
  • Is there any way to bind data to data.frame by some index?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How can i traverse a binary tree from right to left in java?
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal