Re: [R] Joining two files

2012-11-23 Thread Rui Barradas
Hello, So you need a function that can rbind and also return the total unique columns. It's a bit more complicated but I think this does what you want. ADD <- function(x, y){ cx <- colnames(x) cy <- colnames(y) if(is.null(cx) || is.null(cy)){ d <- length(cx) - length(cy)

Re: [R] Joining two files

2012-11-23 Thread David L Carlson
iday, November 23, 2012 10:56 AM > To: Virgile Capo-Chichi > Cc: R help > Subject: Re: [R] Joining two files > > Hi, > Try this: > > r1<-c(1,1,2,3) >  r2<-c(2,1,2,2) >  r3<-c(2,1,4,1) >  data1<-data.frame(r1,r2) >  data2<-data.frame(r1,r3) > data1$r

Re: [R] Joining two files

2012-11-23 Thread Virgile Capo-Chichi
3 NA 1 > A.K. > > > > - Original Message - > From: Virgile Capo-Chichi > To: r-help@r-project.org > Cc: > Sent: Friday, November 23, 2012 10:57 AM > Subject: Re: [R] Joining two files > > Thanks Jim for your help. Your results are not what I wanted. I would

Re: [R] Joining two files

2012-11-23 Thread arun
NA  4 #8  3 NA  1 A.K. - Original Message - From: Virgile Capo-Chichi To: r-help@r-project.org Cc: Sent: Friday, November 23, 2012 10:57 AM Subject: Re: [R] Joining two files Thanks Jim for your help. Your results are not what I wanted. I would like to see something like the matrix below.

Re: [R] Joining two files

2012-11-23 Thread Anthony Damico
library(reshape) ?rbind.fill On Fri, Nov 23, 2012 at 10:57 AM, Virgile Capo-Chichi wrote: > Thanks Jim for your help. Your results are not what I wanted. I would like > to see something like the matrix below. This is what I would get if I used > the ADD Files command in SPSS. V > > r1 r2 r3 >

Re: [R] Joining two files

2012-11-23 Thread Virgile Capo-Chichi
Thanks Jim for your help. Your results are not what I wanted. I would like to see something like the matrix below. This is what I would get if I used the ADD Files command in SPSS. V r1 r2 r3 1 2 NA 1 1 NA 2 2 NA 3 2 NA 1 NA 2 1 NA 1 2 NA 4 3 NA 1 2012/11/23 jim holtman > You

Re: [R] Joining two files

2012-11-23 Thread Rui Barradas
Hello, I don't believe there's an R function that does what you want, but you can write one. myrbind <- function(x, y){ cx <- colnames(x) cy <- colnames(y) if(is.null(cx) || is.null(cy)){ result <- rbind(x, y) }else{ ox <- order(cx) oy <- order(cy)

Re: [R] Joining two files

2012-11-23 Thread jim holtman
You did not specify what you were expecting as output. Here is one way of using 'merge', but I am not sure if this is what you were after: > r1<-c(1,1,2,3) > r2<-c(2,1,2,2) > r3<-c(2,1,4,1) > data1<-data.frame(r1,r2) > data2<-data.frame(r1,r3) > data1 r1 r2 1 1 2 2 1 1 3 2 2 4 3 2 > dat

Re: [R] Joining two files

2012-11-23 Thread Virgile Capo-Chichi
Hi Jim, I did not try merge because I thought it only adds variables instead of cases. Below is what I am trying to do. When I joined data1 and data2, I was was expecting three variables: r1, r2 and r3 with r2 and r3 presenting missing values where they did not exist in the first place. V > r1<-c(

Re: [R] Joining two files

2012-11-23 Thread jim holtman
Have you tried 'merge'? You did not provide any sample data (use 'dput' if you do) so that we could show a possible solution. On Fri, Nov 23, 2012 at 9:56 AM, Virgile Capo-Chichi wrote: > Hello all, > I al trying to join (ADD FILES in SPSS) two files using the rbind() > function. However, with r

[R] Joining two files

2012-11-23 Thread Virgile Capo-Chichi
Hello all, I al trying to join (ADD FILES in SPSS) two files using the rbind() function. However, with rbind() R does not behave the same way as SPSS. I mean, it just concatenates the two blocs with no consideration for same variables if these are not in the same position in the two files. Anyone k