Here is one way of doing it:

> x <- read.table(textConnection("CFISCA                FIRMS
YEAR           VAR        VALUE
+ 20345                     nike            2005            EC01         34
+ 20345                     nike            2006           EC01         45
+ 56779                    mediaset   2005           EC01         65
+ 64568                   agazzini     2005           EC01         78
+ 64568                    agazzini    2006        EC01           56
+ 78907                 uniteam       2006       EC01          46"),
header=TRUE)
> closeAllConnections()
> # split by FIRMS and only keep those that have two entries
> result <- do.call(rbind, lapply(split(x, x$FIRMS), function(.firm){
+     if (nrow(.firm) != 2) return(NULL)
+     else return(.firm)
+ }))
>
> result
           CFISCA    FIRMS YEAR  VAR VALUE
agazzini.4  64568 agazzini 2005 EC01    78
agazzini.5  64568 agazzini 2006 EC01    56
nike.1      20345     nike 2005 EC01    34
nike.2      20345     nike 2006 EC01    45
>


On Wed, Apr 21, 2010 at 10:32 AM, n.via...@libero.it <n.via...@libero.it>wrote:

>
> Dear list,
> >I have a question about the selection of Variables in dataframes.
> >I have a dataframes like this:
> >
> >CFISCA                FIRMS        YEAR           VAR        VALUE
> >20345                     nike            2005            EC01         34
> >20345                     nike            2006           EC01         45
> >56779                    mediaset   2005           EC01         65
> >64568                   agazzini     2005           EC01         78
> >64568                    agazzini    2006        EC01           56
> >78907                 uniteam       2006       EC01          46
> >
> >
> >what my result should be is a new dataframes which have only firms which
> have
> >data in both years (2005,2006)
> >
> >CFISCA       FIRMS    YEAR       VAR    VALUE
> >20345          nike         2005       EC01        34
> >20345          nike        2006      EC01         45
> >64568        agazzini  2005      EC01         78
> >64568      agazzini    2006     EC01         56
> >
> >
> >Thanks for your attention!!!
>
>
>
>
>        [[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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[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