Tammy,

# use the function dput() to provide code for us to easily recreate your
example data
crosspries <- list(structure(list(Product = c("A", "B", "C"), Year_Month =
c(201208L,
 201208L, 201208L), prod1 = c(1L, 2L, 1L)), .Names = c("Product",
"Year_Month", "prod1"), class = "data.frame", row.names = c(NA,
 -3L)), structure(list(Product = c("A", "B", "D", "F"), Year_Month =
c(201209L,
201209L, 201209L, 201209L), prod1 = c(1L, 2L, 1L, 2L), prod2 = c(1L,
 2L, 1L, 1L)), .Names = c("Product", "Year_Month", "prod1", "prod2"
), class = "data.frame", row.names = c(NA, -4L)))

# merge the two data frames
df1 <- merge(crosspries[[1]], crosspries[[2]], all=TRUE)

# create a new data frame with all possible combinations of Product and
Year_Month
template <- expand.grid(Product=unique(df1$Product),
Year_Month=unique(df1$Year_Month))

# merge the data with the template
df2 <- merge(df1, template, all=TRUE)
df2

Jean


On Thu, Jan 24, 2013 at 5:25 AM, Tammy Ma <metal_lical...@live.com> wrote:

>
> HI,
>
>
> I have the following list:
>
> crosspries
> $crosspries[[1]]
>        Product         Year_Month   prod1
>           A                  201208        1
>           B                  201208        2
>           C                  201208        1
>
>
> $crosspries[[2]]
>      Product       Year_Month    prod1   prod2
>         A               201209         1          1
>         B               201209         2          2
>         D              201209          1          1
>         F              201209          2          1
>
> I want to get the following dataframe:
>
>
> Product   Year_Month     prod1    prod2
>    A         201208             1           NA
>    B          201208             2           NA
>   C          201208              1           NA
>   D           201208             NA          NA
>   F            201208             NA          NA
>   A         201209             1             1
>   B         201209             2             2
>   C        201209             NA           NA
>   D        201209             1              1
>   F        201209             2              1
>
>
>
> How can I get it in r?
>
>
> Thanks.
>
> Kind regards,
> Tammy
>
>
>
>
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to