[R] combine vector and data frame on field?

Henrique Dallazuanna wwwhsd at gmail.com
Tue Feb 26 16:01:35 CET 2008


Try this:

merge(tsus_same_mean, as.data.frame(tsuPIDCount), by.x="PID", by.y=0)


On 26/02/2008, Karin Lagesen <karin.lagesen at medisin.uio.no> wrote:
>
>  I have managed to create a data frame like this:
>
>
>  > tsus_same_mean[1:10,]
>      PID            Grp        Dist   PercAln    PercId
>  1  12638  Acidobacteria 0.000000000 1.0000000 1.0000000
>  2     87 Actinobacteria 0.000000000 0.9700000 0.9700000
>  3     92 Actinobacteria 0.008902000 1.0000000 0.9910000
>  4     94 Actinobacteria 0.000000000 1.0000000 1.0000000
>  5    189 Actinobacteria 0.005876733 0.9733333 0.9676667
>  6    242 Actinobacteria 0.001734200 0.9733333 0.9715333
>  7    305 Actinobacteria 0.000000000 0.9700000 0.9700000
>  8    307 Actinobacteria 0.000000000 0.9700000 0.9700000
>  9    328 Actinobacteria 0.000000000 1.0000000 1.0000000
>  10 10689 Actinobacteria 0.000000000 1.0000000 1.0000000
>  >
>
>  and what I think is a factor like this:
>
>  > tsuPIDCount[1:10]
>   3  4  5  8  9 12 13 15 18 19
>   2  2  2  3  4  7  4  2  2  3
>  >
>
>  Now, I'd like to combine the two. The factor levels in tsuPIDCount
>  corresponds to the field called PID in the data frame.
>
>  Any hints on how to do this? cbind just adds the vector onto the end,
>  and I couldn't quite figure out if I could somehow say that the level
>  should correspond to the PID.
>
>  Thanks a lot for your helpin advance:)
>
>  Karin
>  --
>  Karin Lagesen, PhD student
>  karin.lagesen at medisin.uio.no
>  http://folk.uio.no/karinlag
>
>  ______________________________________________
>  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.
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list