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

Jessica Streicher j.streicher at micromata.de
Fri Aug 3 18:19:33 CEST 2012


?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.



More information about the R-help mailing list