[R] how to identify values from a column of a dataframe, and insert them in other data.frame with the corresponding id?

Petr PIKAL petr.pikal at precheza.cz
Mon Aug 6 12:12:13 CEST 2012


Hi

It is better to use dput for presenting data for others. You probably want 
?merge.

Something like

merge(datuak, datuak2, by = "calee_id", all.x=TRUE)

However calee_id seems to be a floating point number and it may be rounded 
so you shall beware of it. 

Regards
Petr

 
> Thank you very much John, can you read it now?
> 
> <Hello,
> 
> <I'd like to do next, see if you could help me please:
> <I have a csv called "datuak" with a id called "calee_id" and a colunm
> called "poids".
> <I have another csv called "datuak2" with the same id called "calee_id",
> (although there are "calee_id" that are in "datuak" but not in "datuak2"
> and inverse), and a column called "kg_totales" in which the values are
> repeteated for each calee_id because are the sum of the colum "kg" for
> each row.
> 
> <I show you the table "datuak" and "datuak2":
> 
> <Datuak (in the example the calee_id is the same, but there are a lot):
> 
> <   poids   calee_id   maree_id
> <   10   1.27E+12   0.3013157
> <   20   1.27E+12   0.05726046
> <   20   1.27E+12   0.73631699
> <   25   1.27E+12   0.74492002
> <   3   1.27E+12   0.74492002
> <   27   1.27E+12   0.31776439
> <   43   1.27E+12   0.31776439
> 
> 
> <Datuak2:
> 
> <           calee_id          maree_id      kg_totales  effectif
> <1     1.33959e+12 0.782835873      129.7             30
> <2     1.33959e+12 0.782835873      129.7             40
> <3     1.33959e+12 0.782835873      129.7             10
> <4     1.33959e+12 0.782835873      129.7              5
> <5     1.33959e+12 0.782835873      129.7            1.7
> <6     1.33959e+12 0.782835873      129.7             20
> <7     1.33959e+12 0.782835873      129.7             20
> <8     1.33959e+12 0.782835873      129.7              1
> <9     1.33959e+12 0.782835873      129.7              2
> 
> <I would like to identify in the csv "datuak2" the corresponding
> "calee_id" that also are in "datuak", and create a new column in
> "datuak" with the values for each "calee_id" from "kg_totales", and not
> repeat them.
> <So the final table would be "datuak", with "calee_id", "poids", and the
> new column "kg_totales" with its corresponding value for each row.
> 
> <Thank you very much,
> <Nerea
> 
> -----Mensaje original-----
> De: John Kane [mailto:jrkrideau at inbox.com] 
> Enviado el: 03 August 2012 20:17
> Para: Nerea Lezama; r-help at r-project.org
> Asunto: RE: [R] how to identify values from a column of a dataframe, and
> insert them in other data.frame with the corresponding id?
> 
> Hi Nerea,
> 
> For some reason your post is badl garbled and close to imposible to
> read. 
> Perhaps you need to check your text encoding?
> 
> Also to send sample data it is better to use the dput() command.
> Do dput(myfile) and then paste the results into your email
> 
> Sorry not to be of more help.
> 
> John Kane
> Kingston ON Canada
> 
> 
> > -----Original Message-----
> > From: nlezama at azti.es
> > Sent: Fri, 3 Aug 2012 12:34:07 +0200
> > To: r-help at r-project.org
> > Subject: [R] how to identify values from a column of a dataframe, and 
> > insert them in other data.frame with the corresponding id?
> > 
> > 
> > 
> > Hello,
> > 
> > Ib??d like to do next, see if you could help me please:
> > I have a csv called b??datuakb?? with a id called b??calee_idb?? and a
> 
> > colunm called b??poidsb??.
> > 
> > I have another csv called b??datuak2b?? with the same id called 
> > b??calee_idb??, (although there are b??calee_idb?? that are in 
> > b??datuakb?? but not in b??datuak2b?? and inverse), and a column 
> > called b??kg_totalesb?? in which the values are repeteated for each 
> > calee_id because are the sum of the colum b??kgb?? for each row.
> > 
> > 
> > 
> > I show you the table b??datuakb?? and b??datuak2b??:
> > 
> > 
> > 
> > Datuak (in the example the calee_id is the same, but there are a lot):
> > 
> > 
> > 
> >    poids
> > 
> > calee_id
> > 
> > maree_id
> > 
> >    10
> > 
> > 1.27E+12
> > 
> > 0.3013157
> > 
> >    20
> > 
> > 1.27E+12
> > 
> > 0.05726046
> > 
> >    20
> > 
> > 1.27E+12
> > 
> > 0.73631699
> > 
> >    25
> > 
> > 1.27E+12
> > 
> > 0.74492002
> > 
> >    3
> > 
> > 1.27E+12
> > 
> > 0.74492002
> > 
> >    27
> > 
> > 1.27E+12
> > 
> > 0.31776439
> > 
> >    43
> > 
> > 1.27E+12
> > 
> > 0.31776439
> > 
> > 
> > 
> > 
> > 
> > Datuak2:
> > 
> > 
> > 
> >            calee_id          maree_id      kg_totales  effectif
> > 
> > 1     1.33959e+12 0.782835873      129.7             30
> > 
> > 2     1.33959e+12 0.782835873      129.7             40
> > 
> > 3     1.33959e+12 0.782835873      129.7             10
> > 
> > 4     1.33959e+12 0.782835873      129.7              5
> > 
> > 5     1.33959e+12 0.782835873      129.7            1.7
> > 
> > 6     1.33959e+12 0.782835873      129.7             20
> > 
> > 7     1.33959e+12 0.782835873      129.7             20
> > 
> > 8     1.33959e+12 0.782835873      129.7              1
> > 
> > 9     1.33959e+12 0.782835873      129.7              2
> > 
> > I would like to identify in the csv b??datuak2b?? the corresponding 
> > b??calee_idb?? that also are in b??datuakb??, and create a new column 
> > in b??datuakb?? with the values for each b??calee_idb?? from 
> > b??kg_totalesb??, and not repeat them.
> > 
> > So the final table would be b??datuakb??, with b??calee_idb??, 
> > b??poidsb??, and the new column b??kg_totalesb?? with its 
> > corresponding value for each row.
> > 
> > 
> > 
> > Thank you very much,
> > 
> > Nerea
> > 
> > 
> > 
> > 
> > 
> > 
> > --
> > 
> > 
> > 
> > 
> >    [[alternative HTML version deleted]]
> > 
> > ______________________________________________
> > R-help at r-project.org mailing list
> > 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.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.



More information about the R-help mailing list