Thank you all by  your comments. I will soon try out the suggested
solutions.


Abraço forte e que a força esteja com você,

Dr. Pedro Emmanuel A. A. do Brasil
Instituto de Pesquisa Clínica Evandro Chagas
Fundação Oswaldo Cruz
Rio de Janeiro - Brasil
Av. Brasil 4365
Tel 55 21 3865-9648
email: pedro.bra...@ipec.fiocruz.br
email: emmanuel.bra...@gmail.com

---Apoio aos softwares livres
www.zotero.org - gerenciamento de referências bibliográficas.
www.broffice.org ou www.openoffice.org - textos, planilhas ou apresentações.
www.epidata.dk - entrada de dados.
www.r-project.org - análise de dados.
www.ubuntu.com/ - sistema operacional


2010/7/15 Jordi <jorp...@gmail.com>

> Hi all!
> My english is not very good. Sorry.
>
> If all your data is numeric you can solve yor problem doing this:
> For example:
>
> DATA:
> k1<-matrix(c(1,NA,NA,4,NA,6,NA,NA), ncol=2, byrow=T)
> dimnames(k1)<-list(c("ind1","ind2","ind3","ind4"),c("var1","var2"))
> k2<-matrix(c(NA,2,NA,NA,5,NA,NA,8), ncol=2, byrow=T)
> dimnames(k1)<-list(c("ind1","ind2","ind3","ind4"),c("var1","var2"))
> k3<-matrix(c(NA,NA,3,NA,NA,NA,7,NA), ncol=2, byrow=T)
> dimnames(k1)<-list(c("ind1","ind2","ind3","ind4"),c("var1","var2"))
> SOLUTION:
> k13<-array(c(k1,k2,k3),dim=c(4,2,3))
> apply(k13,c(1,2),sum, na.rm=T)
>
>
>  If you have character data, you can try to do this:
> For example:
>
> DATA:
> k1<-matrix(c("A",NA,NA,"D",NA,"F",NA,NA), ncol=2, byrow=T)
> dimnames(k1)<-list(c("ind1","ind2","ind3","ind4"),c("var1","var2"))
> k2<-matrix(c(NA,"B",NA,NA,"E",NA,NA,"H"), ncol=2, byrow=T)
> dimnames(k1)<-list(c("ind1","ind2","ind3","ind4"),c("var1","var2"))
> k3<-matrix(c(NA,NA,"C",NA,NA,NA,"G",NA), ncol=2, byrow=T)
> dimnames(k1)<-list(c("ind1","ind2","ind3","ind4"),c("var1","var2"))
> SOLUTION:
> k13<-array(c(k1,k2,k3),dim=c(4,2,3))
> select<-function(a){a[!is.na(a)]}
> apply(k13,c(1,2),select)
>
>
>
>
> 2010/6/24 Aidan Findlater <ai...@aidanfindlater.com>
>
> Hi Pedro,
>>
>> I believe that the following should do what you want:
>>
>> ----start----
>>
>> # Copy over to fill the NAs
>> # Gets all Q16.x values that are set to NA, and assigns the equivalent
>> Q16.y
>> values
>> f$Q16.x[is.na(f$Q16.x)] <- f$Q16.y[is.na(f$Q16.x)]
>> f$Q17.x[is.na(f$Q17.x)] <- f$Q17.y[is.na(f$Q17.x)]
>>
>> # Keep and rename the columns we want
>> f <- f[,c("NIU", "Q16.x", "Q17.y")]
>> names(f) <- c("NIU", "Q16", "Q17")
>>
>> ----end----
>>
>> Let me know if it doesn't work as it should.
>>
>> -Aidan
>>
>> On Thu, Jun 24, 2010 at 3:17 PM, Pedro Emmanuel Alvarenga Americano do
>> Brasil <emmanuel.bra...@gmail.com> wrote:
>>
>> > Hello R friends,
>> >
>> > I would like to know if anyone could give me a tip of a function to
>> merge
>> > two data frames but updating NA fields. Any script that I could work on
>> > would be fine too.
>> >
>> > I have two datasets which each one is from different physicians
>> evaluating
>> > the same subjects. The two data frames have the same variables. I woud
>> like
>> > to merge them but the second data frame 'inputing' its data on the empty
>> > filds of the first one. I tried the merge function, but it does not work
>> as
>> > I would like to. I found other merge functions and a combine (Hmisc) but
>> I
>> > coudnt get it done so far. I did it very long ago using Stata (whith a
>> > command called joinby), but a I couldnt find any like that in R. An
>> example
>> > below...
>> >
>> >
>> > >c1
>> > NIU    Q16  Q17
>> > 1      SIM  *SIM
>> > *2      *NA*   NAO
>> > 3      NAO  SIM
>> > 4*      NA   NA*
>> > 5      SIM  NAO
>> >
>> > c2
>> > NIU    Q16  Q17
>> > 1      SIM  *NAO*
>> > 2      *NAO*  NAO
>> > 3      NAO  SIM
>> > 4  *    SIM  SIM*
>> > 5      NA   NA
>> >
>> > f <- merge(c1,c2,by.x='NIU',by.x='NIU',all.x=T,all.y=F)
>> > f # using base::merge would give something like this ...
>> >
>> > NIU    Q16.x  Q17.x  Q16.y  Q17.y
>> > 1      SIM    SIM    SIM    NAO
>> > 2      NA     NAO    NAO    NAO
>> > 3      NAO    SIM    NAO    SIM
>> > 4      NA     NA     SIM    SIM
>> >  5      SIM    NAO    NA     NA
>> >
>> >
>> > f # but I would like something like this...
>> >
>> > NIU    Q16  Q17
>> > 1      SIM  *SIM
>> > *2      *NAO*  NAO
>> > 3      NAO  SIM
>> > 4      SIM  SIM
>> > 5      SIM  NAO
>> >
>> > Any tip?
>> >
>> > Kind regards,
>> >
>> > Abraço forte e que a força esteja com você,
>> >
>> > Dr. Pedro Emmanuel A. A. do Brasil
>> > Instituto de Pesquisa Clínica Evandro Chagas
>> > Fundação Oswaldo Cruz
>> > Rio de Janeiro - Brasil
>> > Av. Brasil 4365
>> > Tel 55 21 3865-9648
>> > email: pedro.bra...@ipec.fiocruz.br
>> > email: emmanuel.bra...@gmail.com
>> >
>> > ---Apoio aos softwares livres
>> > www.zotero.org - gerenciamento de referências bibliográficas.
>> > www.broffice.org ou www.openoffice.org - textos, planilhas ou
>> > apresentações.
>> > www.epidata.dk - entrada de dados.
>> > www.r-project.org - análise de dados.
>> > www.ubuntu.com/ - sistema operacional
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> >
>> > _______________________________________________
>> > R-sig-Epi@stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-epi
>> >
>> >
>>
>>        [[alternative HTML version deleted]]
>>
>>
>> _______________________________________________
>> R-sig-Epi@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-epi
>>
>>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Epi@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-epi

Reply via email to