Re: [R] Merging dataframes

2018-05-02 Thread Thierry Onkelinx
Have a look at anti_join() from the dplyr package. It does exactly what you want. Here is an example based on the code of Robin Table_A <- as.data.frame(Table_A, stringsAsFactors = FALSE)That is Table_B <- as.data.frame(Table_B, stringsAsFactors = FALSE) library(dplyr) anti_join(Table_A, Table_B,

Re: [R] Merging dataframes

2018-05-02 Thread Dr. Robin Haunschild
Hi, I'll coded your example into R code: Table_A <- c('a...@gmail.com', 'John Chan', '0909') Table_A <- rbind(Table_A, c('b...@yahoo.com', 'Tim Ma', '89089')) colnames(Table_A) <- c('Email', 'Name', 'Phone') Table_A Table_B <- c('a...@gmail.com', 'John Chan', 'M', '0909') Table_B <- rbind(Table_

Re: [R] Merging dataframes

2018-05-02 Thread Chintanu
Thanks - Peter, Eivind, Rui Sorry, I perhaps could not explain it properly in the first go. Trying to simplify it here with an example - Say I have two dataframes as below that are NOT equally-sized data frames (i.e., number of columns are different in each table): Table_A: Email

Re: [R] Merging dataframes

2018-05-01 Thread Sarmah, Chintanu
...@r-project.org<mailto:r-help@r-project.org>t 9:05 PM Subject: Re: [R] Merging dataframes To: Rui Barradas mailto:ruipbarra...@sapo.pt>> Cc: Chintanu mailto:chint...@gmail.com>>, R help mailto:r-help@r-project.org>> I'd expect more like setdiff(A$key, B$key) and

Re: [R] Merging dataframes

2018-05-01 Thread Eivind K. Dovik
On Tue, 1 May 2018, Chintanu wrote: Hi, May I please ask how I do the following in R. Sorry - this may be trivial, but I am struggling here for this. For two dataframes (A and B), I wish to identify (based on a primary key-column present in both A & B) - 1. Which records (rows) of A did no

Re: [R] Merging dataframes

2018-05-01 Thread peter dalgaard
I'd expect more like setdiff(A$key, B$key) and vice versa. Or, if you want the actual rows A[!(A$key %in% B$key),] or for the row numbers which(!(A$key %in% B$key)) -pd > On 1 May 2018, at 12:48 , Rui Barradas wrote: > > Hello, > > Is it something like this that you want? > > x <- d

Re: [R] Merging dataframes

2018-05-01 Thread Rui Barradas
Hello, Is it something like this that you want? x <- data.frame(a = c(1:3, 5, 5:10), b = c(1:7, 7, 9:10)) y <- data.frame(a = 1:10, b = 1:10) which(x != y, arr.ind = TRUE) Hope this helps, Rui Barradas On 5/1/2018 11:35 AM, Chintanu wrote: Hi, May I please ask how I do the following in R

[R] Merging dataframes

2018-05-01 Thread Chintanu
Hi, May I please ask how I do the following in R. Sorry - this may be trivial, but I am struggling here for this. For two dataframes (A and B), I wish to identify (based on a primary key-column present in both A & B) - 1. Which records (rows) of A did not match with B, and 2. Which records

Re: [R] merging dataframes in a list

2016-06-06 Thread MacQueen, Don
I would probably do it this way, tmp <- list(data.frame(name="sample1", red=20), data.frame(name="sample1", green=15), data.frame(name="sample2", red=10), data.frame(name="sample2", green=30)) fun1 <- function(df) data.frame(name=df$name, color=names(df)[2], va

Re: [R] merging dataframes in a list

2016-06-04 Thread jim holtman
Here is how you can to it with tidyr: > x <- list(data.frame(name="sample1", red=20) + , data.frame(name="sample1", green=15) + , data.frame(name="sample2", red=10) + , data.frame(name="sample2", green=30) + ) > library(dplyr) > library(tidyr) > > # convert to 'name, type, value';

Re: [R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
Thanks, ldply got me a data frame straight away. But it filled empty spaces with NA and merge no longer works. > ldply(mylist) name red green 1 sample1 20NA 2 sample1 NA15 3 sample2 10NA 4 sample2 NA30 > mydf <- ldply(mylist) > merge(mydf[1,],mydf[2,]) [1] name red gre

Re: [R] merging dataframes in a list

2016-06-03 Thread ruipbarradas
Hello, Sorry, forget my first answer, I misunderstood what you wanted. Let's try again. First of all you have a typo in your second sample2, you wrote 'sample 2' with a space. Now try this. fun2 <- function(n){     merge(lst[[n]], lst[[n + 1]]) } N <- which(seq_along(lst) %% 2 == 1) lst2 <- l

Re: [R] merging dataframes in a list

2016-06-03 Thread Ulrik Stervbo
You can use ldply in the plyr package to bind all the data.frames together (a regular loop will also work). Afterwards you can summarise using ddply Hope this helps Ulrik Ed Siefker schrieb am Fr., 3. Juni 2016 21:10: > aggregate isn't really what I want. Maybe tapply? I still can't get > it

Re: [R] merging dataframes in a list

2016-06-03 Thread ruipbarradas
Hello, Maybe something like the following. lst <- list(data.frame(name="sample1", red=20), data.frame(name="sample1", green=15), data.frame(name="sample2", red=10), data.frame(name="sample 2", green=30)) fun <- function(DF){     data.frame(name = DF[, 1], color = colnames(DF)[2], colnum = DF

Re: [R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
aggregate isn't really what I want. Maybe tapply? I still can't get it to work. > length(mylist) [1] 4 > length(names) [1] 4 > tapply(mylist, names, merge) Error in tapply(mylist, names, merge) : arguments must have same length I guess because a list isn't an atomic data type. What function wi

Re: [R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
I manually constructed the list of sample names and tried the aggregate call I mentioned. Merge works when called manually, but not when using aggregate. > mylist <- list(data.frame(name="sample1", red=20), data.frame(name="sample1", > green=15), data.frame(name="sample2", red=10), data.frame(na

[R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
I have a list of data as follows. > list(data.frame(name="sample1", red=20), data.frame(name="sample1", > green=15), data.frame(name="sample2", red=10), data.frame(name="sample 2", > green=30)) [[1]] name red 1 sample1 20 [[2]] name green 1 sample115 [[3]] name red 1 sample

Re: [R] merging dataframes with an unequal number of variables

2009-10-07 Thread Gabor Grothendieck
See ?rbind.fill in the plyr package. On Wed, Oct 7, 2009 at 9:32 AM, christiaan pauw wrote: > Hallo Everyone > I have the kind of problem that one should never have because one must > always plan well and communicate with your team. But now I haven't so here > is my problem. > > I have data comin

[R] merging dataframes with an unequal number of variables

2009-10-07 Thread christiaan pauw
Hallo Everyone I have the kind of problem that one should never have because one must always plan well and communicate with your team. But now I haven't so here is my problem. I have data coming in on a daily basis from surveys in 10 towns. The questionnaire has 62 variables but some of the region