[R] Extracting data from a file containing data

Peter Tuju peterenos at ymail.com
Thu Jul 2 16:51:07 CEST 2015


Dear Jim,Thank you very much indeed. Its a great job you have done and I really appreciate.Thank you so much.
 _____________
Peter  E. Tuju
Dar es Salaam
T A N Z A N I A
----------------------
      From: jim holtman <jholtman at gmail.com>
 To: Peter Tuju <peterenos at ymail.com> 
Cc: "r-help at r-project.org" <r-help at r-project.org> 
 Sent: Thursday, July 2, 2015 3:49 AM
 Subject: Re: [R] Extracting data from a file containing data
   
Here is a way to do case I.  It uses the 'tidyr' package and produces results like:
> case1[[1]]     YR JF-R_NINO1.2 MAM-R_NINO1.2 JJA-R_NINO1.2 OND-R_NINO1.21  1982           ML            ML            ME            SE2  1983           SE            SE            SE            ME3  1984           ML            ML            ML            ML4  1985           SL            SL            SL            ML5  1986           ME            ML            ML            ME6  1987           ME            SE            SE            SE7  1988           ML            ML            SL            SL8  1989           ML            ML            ML            ML9  1990           ML            ML            ML            ML10 1991           ML            ML            ME            ME11 1992           ME            SE            ME            ML12 1993           ME            ME            ME            ME13 1994           ML            SL            ML            ME14 1995           ME            ML            ML            ML15 1996           ML            SL            SL            SL16 1997           ML            SE            SE            SE17 1998           SE            SE            SE            ML18 1999           ML            ML            SL            ML19 2000           ML            ML            ML            ML20 2001           ML            ME            ML            SL21 2002           ML            ME            ML            ME22 2003           ML            SL            ML            ME23 2004           ML            ML            SL            ME24 2005           ML            ML            ML            ML25 2006           ME            ML            ME            SE26 2007           ME            SL            SL            SL27 2008           ML            ME            ME            ML28 2009           ML            ME            ME            ME29 2010           ME            ME            SL            SL30 2011           ML            ME            ME            ML31 2012           ML            ME            ME            ML



Jim Holtman
Data Munger Guru
 
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
On Fri, Jun 26, 2015 at 5:27 AM, Peter Tuju <peterenos at ymail.com> wrote:

Dear Jim Holtman,
Thank you very much for your help. 
Theproblem I'm trying to solve is “To determine weather the evolutionof ENSO can influence rainfall over Tanzania”. In this study I havetwo types of data, ie Rainfall data (for 23 stations) and Ninoindices data, both spanning a period of 31 years (1982-2012). 
CASEI:1.In “Nino.indices.txt” data for all columns of the ninoregions (both for anomalies and SST), to calculate the Season means"January & February (JF)", “March, April and may(MAM)", "June, July & August (JJA)" and "October,November and December (OND" for each year. and have the outputin table form as;
Ninoindices Mean
|  Years  |  JF SST Mean NINO1+2  |  JF ANOM Mean NINO1+2  |  MAM SST Mean NINO3  |  MAM ANOM Mean NINO3  |  JJA SST Mean NINO4  |  JJA ANOM Mean NINO4  |  OND SST Mean NINO3.4  |  OND SST Mean NINO3.4  |
|  1982  |  
   |  
   |  
   |  
   |  
   |  
   |  
   |  
   |
|  1983  |  
   |  
   |  
   |  
   |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  
   |  
   |  
   |  
   |  
   |  
   |  
   |
|  - - - -    |  
   |  
   |  
   |  
   |  
   |  
   |  
   |  
   |
|   2012  |  
   |  
   |  
   |  
   |  
   |  
   |  
   |  
   |


2.To use the Yearly anomalies for each column in nino regions toclassify the events as;(i). IfANOM Mean>1, then I assign itto “SE” (Being as Strong El-nino)(ii). If0<ANOMMean<=1 , then Iassign it to “ME” (Being as Moderate El-nino)(iii). IfANOM==0,then I assign it to “NT” (Being as NeutralCondition)(iv). If ANOMMean< (-1),then I assign it to “SL” (Being as Strong La-nina)(v). If-1<=ANOMMean< 0, then I assign it to “ML” (Being as Moderate La-nina)Theoutput have to be in table form as;
FORNINO1+2
|  Years  |  JF ANOM Mean NINO1+2  |  MAM ANOM Mean NINO1+2  |  JJA ANOM Mean NINO1+2  |  OND SST Mean NINO1+2  |
|  1982    |  SE    |  
   |  
   |  
   |
|  1983  |  
   |  
   |  SL  |  
   |
|  - - - -  |  
   |  
   |  
   |  ML  |
|  - - - -  |  
   |  ME  |  
   |  
   |
|  2012  |  
   |  
   |  
   |   SL  |


FORNINO3
|  Years  |  JF ANOM Mean NINO3  |  MAM ANOM Mean NINO3  |  JJA ANOM Mean NINO3  |  OND SST Mean NINO3  |
|  1982    |  SE    |  
   |  
   |  
   |
|  1983  |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  ME  |  
   |  
   |
|  2012  |  
   |  
   |  
   |   SL  |


FORNINO4
|  Years  |  JF ANOM Mean NINO4  |  MAM ANOM Mean NINO4  |  JJA ANOM Mean NINO4  |  OND SST Mean NINO4  |
|  1982    |  SE    |  
   |  
   |  
   |
|  1983  |  
   |  
   |  
   |  
   |
|  - - - -  |  ML  |  
   |  
   |  SL  |
|  - - - -  |  
   |  ME  |  
   |  
   |
|  2012  |  
   |  
   |  
   |   SL  |



FORNINO3.4
|  Years  |  JF ANOM Mean NINO3.4  |  MAM ANOM Mean NINO3.4  |  JJA ANOM Mean NINO3.4  |  OND SST Mean NINO3.4  |
|  1982    |  SE    |  SL  |  
   |  
   |
|  1983  |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  
   |  ML  |  
   |
|  - - - -  |  
   |  ME  |  
   |  
   |
|  2012  |  
   |  
   |  
   |   SL  |



3.To plot the time series graph for each nino regions using the YearlyAnomalies.

CASEII:Consider the Rainfall station data;1. In some files containing the data there are missing data labeledby variable “m”. I want to substitute these missing data withlong term mean.2. Find the rowSum and anomalies of each file containing the data.3. To find the cumsum of the rowSum of each file containing the data.4. Plot the single mass curves ie. Plot(Year, cumsum) for each fileand name its title as the name of the corresponding file name.5. Plot the time series graphs for seasons JF, MAM, JJA and OND foreach file and name give its name as “Time series graph for “nameof the file””6. To find the seasonal correlations for JF, MAM, JJA and OND usingthe anomalies of the rainfall station data and that of each ninoregion indices, and have the results in table form as;
CORRELATIONSOF RAINFALL AND NINO1+2 ANOMALIES
|  Years  |  JF  |  MAM  |  JJA  |  OND  |
|  1982    |  
   |  
   |  
   |  
   |
|  1983  |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  
   |  
   |  
   |
|  2012  |  
   |  
   |  
   |  
   |


CORRELATIONSOF RAINFALL AND NINO3ANOMALIES
|  Years  |  JF  |  MAM  |  JJA  |  OND  |
|  1982    |  
   |  
   |  
   |  
   |
|  1983  |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  
   |  
   |  
   |
|  - - - -  |  
   |  
   |  
   |  
   |
|  2012  |  
   |  
   |  
   |  
   |


CORRELATIONSOF RAINFALL AND NINO4ANOMALIES
|  Years  |  JF  |  MAM  |  JJA  |  OND  |
|  1982    |  
   |  |

...

[Message clipped]  



  
	[[alternative HTML version deleted]]



More information about the R-help mailing list