[R] Data.frame of Different Length

Ogbos Okike g||ted|||e2014 @end|ng |rom gm@||@com
Mon Sep 17 10:35:54 CEST 2018


Dear Jeff,

Yours is like reciting A, B,C or 1, 2, 3 ...

I am greatly relieved.

Many thanks.
Ogbos

On Mon, Sep 17, 2018 at 9:07 AM Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
wrote:

> There are many ways to combine data frames, but the method you have chosen
> is extremely rare because you do not appear to be creating sensible
> relationships in the rows of the data frame, so your final result seems
> unlikely to be understandable by normal interpretation of tabular data. See
> ?merge for more normal ways to combine data frames.
>
> However, with respect to your questions:
>
> 1) The usual way to remove a column is to use negative integer indexing:
> a <- a[ , -2 ]
>
> 2) To add more columns, just do it again with the answer you have. I do
> think you are taking an over-complicated approach:
>
> n <- max( nrow(d1), nrow(d2), nrow(d3))
> ix <- seq.int( n )
> a <- data.frame( d1_date=d1$date[ix], d2_date=d2$date[ix],
> d3_date=d3$date[ix] )
>
> On September 17, 2018 12:17:03 AM PDT, Ogbos Okike <
> giftedlife2014 using gmail.com> wrote:
> >Dear Contributors,
> >
> >I have two data frame of different column lengths. I am trying to have
> >them
> >in one data frame.
> >Using
> >A<-d1$date
> >B<-d2$date
> >a<-data.table(A )[ , I := .I][data.table(B )[ , I := .I], on = "I"]
> >I got
> >1: 2005-01-04  1 2005-01-04
> > 2: 2005-01-19  2 2005-01-19
> > 3: 2005-01-22  3 2005-01-22
> > 4: 2005-02-24  4 2005-02-19
> > 5: 2005-05-09  5 2005-02-24
> > 6: 2005-05-16  6 2005-05-09
> > 7: 2005-06-17  7 2005-05-11
> > 8: 2005-07-17  8 2005-05-16
> > 9: 2005-08-07  9 2005-06-13
> >10: 2005-09-11 10 2005-06-17
> >11: 2005-09-13 11 2005-06-22
> >12: 2005-09-15 12 2005-07-18
> >13:         NA 13 2005-08-03
> >14:         NA 14 2005-08-07
> >15:         NA 15 2005-08-10
> >16:         NA 16 2005-08-25
> >17:         NA 17 2005-09-13
> >18:         NA 18 2005-09-15
> >19:         NA 19 2005-10-13
> >20:         NA 20 2005-12-15
> >which is fine.
> >
> >I have two more problems:
> >1) how to remove the nos 1 to 20 inserted at the middle of the dates.
> >
> >2) how to include more columns.
> >
> >I have about 5 columns of different lengths which I wish to have in one
> >data frame.
> >
> >I will remain grateful if assisted.
> >
> >Best regards
> >Ogbos
> >
> >       [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >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.
>
> --
> Sent from my phone. Please excuse my brevity.
>

	[[alternative HTML version deleted]]




More information about the R-help mailing list