Skip to content
Prev 315933 / 398503 Next

how to read a df like that and transform it?

I don't really understand this data table, but maybe this modification
will give you the idea:


dat <- read.table(text="father  mother  num_daughter    daughter
291     3906    0       NA
275     4219    0       NA
273     4236    1       49410
281     4163    1       49408
274     4226    1       49406
295     3869    2       49403
287     4113    0       NA
295     3871    1       49401
292     3895    4       49396
291     3900    3       49392", header=TRUE)

library(reshape2)
dat$num_daughter <- paste0("daughter", dat$num_daughter)
dcast(dat, ... ~ num_daughter, value.var="daughter")


Best,
Ista
On Wed, Jan 23, 2013 at 7:42 AM, Yao He <yao.h.1988 at gmail.com> wrote: