[R] Excluding fixed number of rows from calculation while summarizing using ddply() function.

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Mon Nov 5 17:35:16 CET 2012


This is not a free do-my-work-for-me forum, this is a help-you-learn-R forum. If you study the solution you have been given until you understand how it works, and combine that with an understanding of indexing from the Introduction to R document that comes with R, you should be able to complete your code the way you want it. Don't abuse the generosity of your helpers.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

siddu479 <onlyfordigitalstuff at gmail.com> wrote:

>Hi Arun,
>
>Thanks for your reply but your script is removing only one row( first
>row
>and last row) for each Unique and StepNo combination and calculating
>mean
>for the rest of rows.
>For below data , your script removing the #'s rows perfectly.
>But in reality I may need to ignore *say first 10 rows and last 20 rows
>for
>each Unique and StepNo combination.
>* for statistics calculation.
> Unique StepNo Data1 Data2
>1      A      1     4     5      #Your script removing this row
>successfully.
>2      A      1     5     6
>3      A      1     7     8    
>4      A      1     3     4      
>5      A      1     1     1      #Your script removing this row
>successfully.
>6      B      1     2     4      #Your script removing this row
>successfully.
>7      B      1     3     5   
>8      B      1     4     5
>9      B      1     5     6
>10    B      1     6     7      #Your script removing this row
>successfully.
>
>Can you modify your script to get my requirement like below (making it
>generic, here *N=2*, removing first 2 lines and last 2 lines..
>*sometimes I
>may have two numbers N1 & N2 (no.of rows need to be removed from and
>top and
>bottom respectively*)
>
> Unique StepNo Data1 Data2
>1      A      1     4     5      #Ignore this
>2      A      1     5     6      #Ignore this
>3      A      1     7     8    
>4      A      1     3     4      #Ignore this
>5      A      1     1     1      #Ignore this
>6      B      1     2     4      #Ignore this
>7      B      1     3     5      #Ignore this
>8      B      1     4     5
>9      B      1     5     6     #Ignore this
>10    B      1     6     7     #Ignore this
>
>and then calculate the statistics using ddply.
>
>I hope my problem statement is much clear now.
>
>
>
>
>
>
>
>-----
>Sidda
>Business Analyst Lead
>Applied Materials Inc.
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Excluding-fixed-number-of-rows-from-calculation-while-summarizing-using-ddply-function-tp4648406p4648447.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>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.




More information about the R-help mailing list