Nerea Lezama
2012-Aug-03 10:34 UTC
[R] how to identify values from a column of a dataframe, and insert them in other data.frame with the corresponding id?
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 -- [[alternative HTML version deleted]]
Jessica Streicher
2012-Aug-03 16:19 UTC
[R] how to identify values from a column of a dataframe, and insert them in other data.frame with the corresponding id?
?merge and ?unique might help however: why is calee_id a floating point number? Ids are usually stuff thats close to a factor, integers, strings and the like, you know stuff that has a value that isn't dependant on precision. Floating points might just complicate things.. On 03.08.2012, at 12:34, Nerea Lezama wrote:> > > 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 > > > > > > > -- > > > > > [[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.
John Kane
2012-Aug-03 18:17 UTC
[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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!