Please help me to combine two datasets.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Please help me to combine two datasets.

Arun.stat
Dear r-users,

Suppose I have two data sets

data set-1

Date          height
------------------------
1/11/2005     10
2/11/2005     23
3/11/2005     54
4/11/2005     21
5/11/2005     22

data set-2

weight
--------
32
45
11


Now I want to combine this two data sets. i.e. i want to see:


Date             height       weight
-------------------------------------------
3/11/2005         54           32
4/11/2005         21           45
5/11/2005         22           11

Can any one give me the required r-code to perform this?

Thanks and regards,
Arun

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Please help me to combine two datasets.

Wincent
?merge maybe is what you want.

2006/5/11, Arun Kumar Saha <[hidden email]>:

> Dear r-users,
>
> Suppose I have two data sets
>
> data set-1
>
> Date          height
> ------------------------
> 1/11/2005     10
> 2/11/2005     23
> 3/11/2005     54
> 4/11/2005     21
> 5/11/2005     22
>
> data set-2
>
> weight
> --------
> 32
> 45
> 11
>
>
> Now I want to combine this two data sets. i.e. i want to see:
>
>
> Date             height       weight
> -------------------------------------------
> 3/11/2005         54           32
> 4/11/2005         21           45
> 5/11/2005         22           11
>
> Can any one give me the required r-code to perform this?
>
> Thanks and regards,
> Arun
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
黄荣贵
Deparment of Sociology
Fudan University


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Please help me to combine two datasets.

Sean O'Riordain-2
In reply to this post by Arun.stat
merge(data.set.1, data.set.2)

but how do I know which rows to drop in ds1?

if data.set.2 had dates, you could say

merge(data.set.1, data.set.2, by.x=Date, by.y=Date, all=T)

or do you just want to drop the first
length(data.set.1)-length(data.set.2) from data.set.1?

do you have NA values?

cheers,
Sean

On 11/05/06, Arun Kumar Saha <[hidden email]> wrote:

> Dear r-users,
>
> Suppose I have two data sets
>
> data set-1
>
> Date          height
> ------------------------
> 1/11/2005     10
> 2/11/2005     23
> 3/11/2005     54
> 4/11/2005     21
> 5/11/2005     22
>
> data set-2
>
> weight
> --------
> 32
> 45
> 11
>
>
> Now I want to combine this two data sets. i.e. i want to see:
>
>
> Date             height       weight
> -------------------------------------------
> 3/11/2005         54           32
> 4/11/2005         21           45
> 5/11/2005         22           11
>
> Can any one give me the required r-code to perform this?
>
> Thanks and regards,
> Arun
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Please help me to combine two datasets.

Sean O'Riordain-2
Hi Arun,

so to clarify: you want to drop the first
  length(data.set.1)-length(data.set.2)
rows...  so you might say...
  new.ds1 <- data.set.1[(-(length(data.set.1)-length(data.set.2)),]
and then add a new column...
  new.ds.combined <- cbind(new.ds1, data.set.2)

cheers,
Sean


On 11/05/06, Arun Kumar Saha <[hidden email]> wrote:

>
> Dear Sean,
>
> Thanks for this reply. But my problem is not solved. Actually I want to drop
> first two rows from dataset-1 and then combine them. Can you give me any
> idea?
>
> Thanks and regards,
> Arun
>
>
>
> On 5/11/06, Sean O'Riordain <[hidden email]> wrote:
> > merge(data.set.1, data.set.2)
> >
> > but how do I know which rows to drop in ds1?
> >
> > if data.set.2 had dates, you could say
> >
> > merge(data.set.1, data.set.2, by.x=Date, by.y=Date, all=T)
> >
> > or do you just want to drop the first
> > length(data.set.1)-length(data.set.2) from data.set.1?
> >
> > do you have NA values?
> >
> > cheers,
> > Sean
> >
> > On 11/05/06, Arun Kumar Saha <[hidden email]> wrote:
> > > Dear r-users,
> > >
> > > Suppose I have two data sets
> > >
> > > data set-1
> > >
> > > Date          height
> > > ------------------------
> > > 1/11/2005     10
> > > 2/11/2005     23
> > > 3/11/2005     54
> > > 4/11/2005     21
> > > 5/11/2005     22
> > >
> > > data set-2
> > >
> > > weight
> > > --------
> > > 32
> > > 45
> > > 11
> > >
> > >
> > > Now I want to combine this two data sets. i.e. i want to see:
> > >
> > >
> > > Date             height       weight
> > > -------------------------------------------
> > > 3/11/2005         54           32
> > > 4/11/2005         21           45
> > > 5/11/2005         22           11
> > >
> > > Can any one give me the required r-code to perform this?
> > >
> > > Thanks and regards,
> > > Arun
> > >
> > >         [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> > >
> >
>
>
>
> --
> Arun Kumar Saha, M.Sc.[C.U.]
> S T A T I S T I C I A N    [Analyst]
> RISK  MANAGEMENT  DIVISION
> Transgraph Consulting [ www.transgraph.com]
> Hyderabad, INDIA
> Contact #  Home: (91-033) 25558038
>                 Office: (91-040) 30685012 Ext. 17
>                   FAX: (91-040) 55755003
>                Mobile: 919849957010
>  E-Mail: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html