Re: [R] Query about calculating the monthly average of daily data columns

2019-09-13 Thread Jim Lemon
Sorry, forgot to include the list.

On Sat, Sep 14, 2019 at 10:27 AM Jim Lemon  wrote:
>
> See inline
>
> On Fri, Sep 13, 2019 at 11:20 PM Subhamitra Patra 
>  wrote:
>>
>> Dear Sir,
>>
>> Yes, I understood the logic. But, still, I have a few queries that I 
>> mentioned below your answers.
>>
>>> "# if you only have to get the monthly averages, it can be done this way
>>> spdat$month<-sapply(strsplit(spdat$dates,"-"),"[",2)
>>> spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",3)"
>>>
>>> B. Here, I need to define the no. of months, and years separately, right? 
>>> or else what 2, and 3 (in bold) indicates?
>>
>>
>> To get the grouping variable of sequential months that you want, you only 
>> need the month and year values of the dates in the first column. First I 
>> used the "strsplit" function to split the date field at the hyphens, then 
>> used "sapply" to extract ("[") the second (month) and third (year) parts as 
>> two new columns. Because you have more than one year of data, you need the 
>> year values or you will group all Januarys, all Februarys and so on. Notice 
>> how I pass both of the new columns as a list (a data frame is a type of 
>> list) in the call to get the mean of each month.
>>
>> 1. Here, as per my understanding, the "3" indicates the 3rd year, right? 
>> But, you showed an average for 2 months of the same year. Then, what "3" in 
>> the  spdat$year object indicate?
>
>
> No, as I explained in the initial email and below, the "strsplit" function 
> takes one or more strings (your dates) and breaks them at the specified 
> character ("-"), So
>
> strsplit("1-1-1994","-")
> [[1]]
> [1] "1""1""1994"
>
> That is passed to the "sapply" function that applies the extraction ("[") 
> operator to the result of "strsplit". The "3" indicates that you want to 
> extract the third element, in this case, the year.
>
> > sapply(strsplit("1-1-1994","-"),"[",3)
> [1] "1994"
>
> So by splitting the dates and extracting the second (month) and third (year) 
> element from each date, we have all the information needed to create a 
> grouping variable for monthly averages.
>
>>
>>
>>> C. From this part, I got the exact average values of both January and 
>>> February of 1994 for country A, and B. But, in code, I have a query that I 
>>> need to define  spdat$returnA, and  spdat$returnB separately before writing 
>>> this code, right? Like this, I need to define for each 84 countries 
>>> separately with their respective number of months, and years before writing 
>>> this code, right?
>>
>>
>> I don't think so. Because I don't know what your data looks like, I am 
>> guessing that for each row, it has columns for each of the 84 countries. I 
>> don't know what these columns are named, either. Maybe:
>>
>> date Australia   Belarus   ...Zambia
>> 01/01/1994   20 21 22
>> ...
>>
>> Here, due to my misunderstanding about the code, I was wrong. But, what data 
>> structure you guessed, it is absolutely right that for each row, I have 
>> columns for each of the 84 countries. So, I think, I need to define the date 
>> column with no. of months, and years once for all the countries. Therefore, 
>> I got my answer to the first and third question in the previous email (what 
>> you suggested) that I no need to define the column of each country, as the 
>> date, and no. of observations are same for all countries. But, the no. of 
>> days are different for each month, and similarly, for each year. So, I think 
>> I need to define date for each year separately.  Hence, I have given an 
>> example of 12 months, for 2 years (i.e. 1994, and 1995), and have written 
>> the following code. Please correct me in case I am wrong.
>>
>>  spdat<-data.frame(
>>   
>> dates=paste(c(1:21,1:20,1:23,1:21,1:22,1:22,1:21,1:23,1:22,1:21,1:22,1:22),c(rep(1,21),rep(2,20),rep(3,23),
>>  rep(4,21), 
>> rep(5,22),rep(6,22),rep(7,21),rep(8,23),rep(9,22),rep(10,21),rep(11,22),rep(12,22)),rep(1994,260)
>>  
>> dates1=paste(c(1:22,1:20,1:23,1:20,1:23,1:22,1:21,1:23,1:21,1:22,1:22,1:21),c(rep(1,22),rep(2,20),rep(3,23),
>>  rep(4,20), 
>> rep(5,23),rep(6,22),rep(7,21),rep(8,23),rep(9,21),rep(10,21),rep(11,22),rep(12,21)),rep(1995,259)
>>  ,sep="-")
>>
> First, you don't have to recreate the data that you already have. I did 
> because I don't have it and have to guess what it looks like. Remember 
> neither I nor any of the others who have offered help have your data or even 
> a representative sample. If you tried the code above, you surely must know 
> that it doesn't work. I could create code that would produce the dates from 
> 1-1-1994 to 31/12/1995 or any other stretch you would like, but it would only 
> confuse you more.  _You already have the dates in your data file._ What I 
> have shown you is how to use those dates to create the grouping variable that 
> you want.
>
>> Concerning the exporting of structure of the dataset to excel, I will have 
>> 12*84 matrix. But, please sugg

Re: [R] A question on regular expression

2019-09-13 Thread Jeff Newmiller
Regular expressions are in much more widespread use than merely R... and there 
are correspondingly more resources for learning than just R-help. Please do 
make use of them. Here are a couple that googling "regex character set carat" 
found:

https://www.regular-expressions.info/charclass.html
https://stackoverflow.com/questions/23352038/regex-excluding-specific-characters

On September 13, 2019 3:59:07 AM PDT, Christofer Bogaso 
 wrote:
>A quick question.
>
>Could you please explain the -- [^}]* -- part in finding the pattern?
>
>On Fri, Sep 13, 2019 at 12:19 AM Bert Gunter 
>wrote:
>>
>>
>> You can't use the same regex for str_extract_all as I used for sub
>(or gsub, which is what is required here)! If you do this sort of thing
>a lot, you *must* learn more about regex's.
>>
>> Anyway, this will do what you want I think:
>>
>> z <- paste("ab{cd$ }ed", "ab{cad$ }ed", collapse = " ")  ## just for
>readability
>>
>> > str_extract_all(z,"\\{[^}]*\\}")
>> [[1]]
>> [1] "{cd$ }"  "{cad$ }"
>>
>> Cheers,
>> Bert
>>
>> On Thu, Sep 12, 2019 at 10:12 AM Christofer Bogaso
> wrote:
>>>
>>> Thanks Bert,
>>>
>>> This works, but if in my text there are more than one patterns then
>>> fails to generate desired result.
>>>
>>> library(stringr)
>>> str_extract_all(paste("ab{cd$ }ed", "ab{cad$ }ed", collapse = " "),
>>> ".*(\\{.*\\}).*")
>>>
>>> This generates below -
>>>
>>> [[1]]
>>>
>>> [1] "ab{cd$ }ed ab{cad$ }ed"
>>>
>>> I was expecting I would get a vector of length 2 with desired
>pattern.
>>>
>>> Where did I make any mistake?
>>>
>>> Thanks,
>>>
>>> On Thu, Sep 12, 2019 at 10:29 PM Bert Gunter
> wrote:
>>> >
>>> > > sub(".*(\\{.*\\}).*", "\\1","ab{cd$ }ed")
>>> > [1] "{cd$ }"
>>> >
>>> > Use ".+" instead of ".*" within the {} if you don't want to return
>empty {}'s.
>>> >
>>> > You might wish to use the stringr package for string matching and
>manipulation, as it provides a more user friendly and consistent
>interface to these tasks.
>>> >
>>> >
>>> > Bert Gunter
>>> >
>>> > "The trouble with having an open mind is that people keep coming
>along and sticking things into it."
>>> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>> >
>>> >
>>> > On Thu, Sep 12, 2019 at 9:31 AM Christofer Bogaso
> wrote:
>>> >>
>>> >> Hi,
>>> >>
>>> >> I am wondering on what is the correct way to select a pattern
>which goes as -
>>> >>
>>> >> {"(any character with any length)"}
>>> >>
>>> >> The expressions " {" " and " "} " both are included in the
>pattern.
>>> >>
>>> >> For example, the lookup of the above pattern in the text "
>>> >> {"asaf455%"}57573blabla " will result in {"asaf455%"}
>>> >>
>>> >> Any help will be highly appreciated.
>>> >>
>>> >> Thanks,
>>> >>
>>> >> __
>>> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> >> 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.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Query about calculating the monthly average of daily data columns

2019-09-13 Thread Subhamitra Patra
Dear PIKAL,

Thank you very much for your suggestion.

I tried your previous suggested code and getting the average value for each
month for both country A, and B. But in your recent email, you are
suggesting not to change the date column to real date. If I am going
through your recently suggested code, i.e.

 "aggregate(value column, list(format(date column, "%m.%Y"), country
column), mean)"

I am getting an Error that "*aggregate(value, list(format(date, "%m.%Y"),
country), mean) : **object 'value' not found"*.

Here, my query "*may I need to define the date column, country column, and
value column separately?"*

Further, I need something the average value result like below in the data
frame

Month   Country A   Country B
Jan 199426.66 35.78
Feb 199426.13 29.14

so that it will be easy for me to export to excel, and to use for the
further calculations.

Please suggest me in this regard.

Thank you.







[image: Mailtrack]

Sender
notified by
Mailtrack

09/13/19,
07:22:53 PM

On Fri, Sep 13, 2019 at 7:03 PM PIKAL Petr  wrote:

> Hi
>
> I am almost 100% sure that you would spare yourself much trouble if you
> changed your date column to real date
>
> ?as.Date
>
> reshape your wide format to long one
> library(reshape2)
> ?melt
>
> to get 3 column data.frame with one date column, one country column and
> one value column
>
> use ?aggregate and ?format to get summary value
>
> something like
> aggregate(value column, list(format(date column, "%m.%Y"), country
> column), mean)
>
> But if you insist to scratch your left ear with right hand accross your
> head, you could continue your way.
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help  On Behalf Of Subhamitra
> > Patra
> > Sent: Friday, September 13, 2019 3:20 PM
> > To: Jim Lemon ; r-help mailing list  > project.org>
> > Subject: Re: [R] Query about calculating the monthly average of daily
> data
> > columns
> >
> > Dear Sir,
> >
> > Yes, I understood the logic. But, still, I have a few queries that I
> mentioned
> > below your answers.
> >
> > "# if you only have to get the monthly averages, it can be done this way
> > > spdat$month<-sapply(strsplit(spdat$dates,"-"),"["*,2*)
> > > spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",*3*)"
> > >
> > > B. Here, I need to define the no. of months, and years separately,
> right?
> > > or else what 2, and 3 (in bold) indicates?
> > >
> >
> > To get the grouping variable of sequential months that you want, you only
> > need the month and year values of the dates in the first column. First I
> used
> > the "strsplit" function to split the date field at the hyphens, then used
> > "sapply" to extract ("[") the second (month) and *third (year)* parts as
> two
> > new columns. Because you have more than one year of data, you need the
> > year values or you will group all Januarys, all Februarys and so on.
> > Notice how I pass both of the new columns as a list (a data frame is a
> type of
> > list) in the call to get the mean of each month.
> >
> > 1. Here, as per my understanding, the "3" indicates the 3rd year, right?
> > But, you showed an average for 2 months of the same year. Then, what "3"
> > in the  spdat$year object indicate?
> >
> >
> > C. From this part, I got the exact average values of both January and
> > > February of 1994 for country A, and B. But, in code, I have a query
> > > that I need to define  spdat$returnA, and  spdat$returnB separately
> > > before writing this code, right? Like this, I need to define for each
> > > 84 countries separately with their respective number of months, and
> > > years before writing this code, right?
> > >
> >
> > I don't think so. Because I don't know what your data looks like, I am
> > guessing that for each row, it has columns for each of the 84 countries.
> I
> > don't know what these columns are named, either. Maybe:
> >
> > date Australia   Belarus   ...Zambia
> > 01/01/1994   20 21 22
> > ...
> >
> > Here, due to my misunderstanding about the code, I was wrong. But, what
> > data structure you guessed, it is absolutely right that for each row, I
> have
> > columns for each of the 84 countries. So, I think, I need to define the
> date
> > column with no. of months, and years once for all the countries.
> > Therefore, I got my answer to the first and third question in the
> previous
> > email (what you suggested) that I no need to define the column of each
> > country, as the date, and no. of observations are same for all countries.
> > But, the no. of days are different for each month, and similarly, for
> each
> > year. So, I think I need to define date for each year separately.
> Hence, I have
> > given an example of 12 months, for 2 years (i.e. 1994, and 1995), and
> have
> > written t

Re: [R] Query about calculating the monthly average of daily data columns

2019-09-13 Thread PIKAL Petr
Hi

I am almost 100% sure that you would spare yourself much trouble if you changed 
your date column to real date

?as.Date

reshape your wide format to long one
library(reshape2)
?melt

to get 3 column data.frame with one date column, one country column and one 
value column

use ?aggregate and ?format to get summary value

something like
aggregate(value column, list(format(date column, "%m.%Y"), country column), 
mean)

But if you insist to scratch your left ear with right hand accross your head, 
you could continue your way.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Subhamitra
> Patra
> Sent: Friday, September 13, 2019 3:20 PM
> To: Jim Lemon ; r-help mailing list  project.org>
> Subject: Re: [R] Query about calculating the monthly average of daily data
> columns
>
> Dear Sir,
>
> Yes, I understood the logic. But, still, I have a few queries that I mentioned
> below your answers.
>
> "# if you only have to get the monthly averages, it can be done this way
> > spdat$month<-sapply(strsplit(spdat$dates,"-"),"["*,2*)
> > spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",*3*)"
> >
> > B. Here, I need to define the no. of months, and years separately, right?
> > or else what 2, and 3 (in bold) indicates?
> >
>
> To get the grouping variable of sequential months that you want, you only
> need the month and year values of the dates in the first column. First I used
> the "strsplit" function to split the date field at the hyphens, then used
> "sapply" to extract ("[") the second (month) and *third (year)* parts as two
> new columns. Because you have more than one year of data, you need the
> year values or you will group all Januarys, all Februarys and so on.
> Notice how I pass both of the new columns as a list (a data frame is a type of
> list) in the call to get the mean of each month.
>
> 1. Here, as per my understanding, the "3" indicates the 3rd year, right?
> But, you showed an average for 2 months of the same year. Then, what "3"
> in the  spdat$year object indicate?
>
>
> C. From this part, I got the exact average values of both January and
> > February of 1994 for country A, and B. But, in code, I have a query
> > that I need to define  spdat$returnA, and  spdat$returnB separately
> > before writing this code, right? Like this, I need to define for each
> > 84 countries separately with their respective number of months, and
> > years before writing this code, right?
> >
>
> I don't think so. Because I don't know what your data looks like, I am
> guessing that for each row, it has columns for each of the 84 countries. I
> don't know what these columns are named, either. Maybe:
>
> date Australia   Belarus   ...Zambia
> 01/01/1994   20 21 22
> ...
>
> Here, due to my misunderstanding about the code, I was wrong. But, what
> data structure you guessed, it is absolutely right that for each row, I have
> columns for each of the 84 countries. So, I think, I need to define the date
> column with no. of months, and years once for all the countries.
> Therefore, I got my answer to the first and third question in the previous
> email (what you suggested) that I no need to define the column of each
> country, as the date, and no. of observations are same for all countries.
> But, the no. of days are different for each month, and similarly, for each
> year. So, I think I need to define date for each year separately.  Hence, I 
> have
> given an example of 12 months, for 2 years (i.e. 1994, and 1995), and have
> written the following code. Please correct me in case I am wrong.
>
>  spdat<-data.frame(
>
> dates=paste(c(1:21,1:20,1:23,1:21,1:22,1:22,1:21,1:23,1:22,1:21,1:22,1:22),c(r
> ep(1,21),rep(2,20),
> rep(3,23), rep(4,21),
> rep(5,22),rep(6,22),rep(7,21),rep(8,23),rep(9,22),rep(10,21),rep(11,22),rep(12
> ,22)
> ),rep(1994,260)
>  dates1=
> paste(c(1:22,1:20,1:23,1:20,1:23,1:22,1:21,1:23,1:21,1:22,1:22,1:21),c(rep(1,2
> 2),rep(2,20),
> rep(3,23), rep(4,20),
> rep(5,23),rep(6,22),rep(7,21),rep(8,23),rep(9,21),rep(10,21),rep(11,22),rep(12
> ,21)
> ),rep(1995,259) ,sep="-")
>
> Concerning the exporting of structure of the dataset to excel, I will have
> 12*84 matrix. But, please suggest me the way to proceed for the large
> sample. I have mentioned below what I understood from your code. Please
> correct me if I am wrong.
> 1. I need to define the date for each year as the no. of days in each month
> are different for each year (as mentioned in my above code). For instance, in
> my data file, Jan 1994 has 21 days while Jan 1995 has 22 days.
> 2. Need to define the date column as character.
> 3. Need to define the monthly average for each month, and year. So, now
> code will be as follows.
> spdat$month<-sapply(strsplit(spdat$dates,"-"),"[",2,3,4,5,6,7,8,9,10,11,12)
>   As I need all months average sequentially.
> spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",3)
>
> Here, this meaning of "3", I am really unable to get.
>
> 4. Need to de

Re: [R] Bug (?): file.copy() erases 'from' file if the "to" file already exists and is a symlinked file

2019-09-13 Thread peter dalgaard
However, notice that cat doesn't protect you in the same way:

Peters-iMac:tst pd$ echo stuff > A
Peters-iMac:tst pd$ ln -s A B
Peters-iMac:tst pd$ ls -l
total 8
-rw-r--r--  1 pd  staff  6 Sep 13 15:20 A
lrwxr-xr-x  1 pd  staff  1 Sep 13 15:20 B -> A
Peters-iMac:tst pd$ cp A B
cp: B and A are identical (not copied).
Peters-iMac:tst pd$ ls -l
total 8
-rw-r--r--  1 pd  staff  6 Sep 13 15:20 A
lrwxr-xr-x  1 pd  staff  1 Sep 13 15:20 B -> A
Peters-iMac:tst pd$ cat A > B
Peters-iMac:tst pd$ ls -l
total 0
-rw-r--r--  1 pd  staff  0 Sep 13 15:20 A
lrwxr-xr-x  1 pd  staff  1 Sep 13 15:20 B -> A

(& I suspect that cp did likewise in early Unices). Bug or not, it would be 
good if we could detect when "from" and "to" refer to the same file, but I'm 
not sure how to do that.

-pd

> On 13 Sep 2019, at 11:56 , Marc Girondot via R-help  
> wrote:
> 
> If file.copy() is used to replace a symlinked file, it erases the original 
> file and does not copy the file. The original file is lost.
> 
> > version
>  _
> platform x86_64-apple-darwin15.6.0
> arch x86_64
> os darwin15.6.0
> system x86_64, darwin15.6.0
> status Patched
> major?? 3
> minor?? 6.1
> year 2019
> month?? 09
> day?? 06
> svn rev?? 77160
> language R
> version.string R version 3.6.1 Patched (2019-09-06 r77160)
> nickname Action of the Toes
> 
> #
> 
> Here is a reproducible example:
> 
> A <- 10
> save(A, file="A.Rdata")
> file.symlink(from="A.Rdata", to="B.Rdata")
> rm(A)
> 
> load(file="B.Rdata")
> print(A)?? # Perfect
> 
> system("ls -l")
> ## -rw-r--r--?? 1 marcgirondot?? staff?? 70 13 sep 11:44 A.Rdata
> ## lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:44 B.Rdata -> 
> A.Rdata
> 
> file.copy(from="A.Rdata", to="B.Rdata", overwrite = TRUE)
> 
> system("ls -l")
> ## -rw-r--r--?? 1 marcgirondot?? staff 0 13 sep 11:44 A.Rdata
> ## lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:44 B.Rdata -> 
> A.Rdata
> 
> ###
> 
> A.Rdata becomes empty: 0B
> The content of A.Rdata is lost
> 
> 
> In terminal the problem does not occur
> 
> 
> marcgirondot$ ls
> A.Rdata
> marcgirondot$ ln -s A.Rdata B.Rdata
> marcgirondot$ ls -l
> -rw-r--r--?? 1 marcgirondot?? staff?? 70 13 sep 11:38 A.Rdata
> lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:38 B.Rdata -> 
> A.Rdata
> marcgirondot$ cp A.Rdata B.Rdata
> cp: B.Rdata and A.Rdata are identical (not copied).
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Query about calculating the monthly average of daily data columns

2019-09-13 Thread Subhamitra Patra
Dear Sir,

Yes, I understood the logic. But, still, I have a few queries that I
mentioned below your answers.

"# if you only have to get the monthly averages, it can be done this way
> spdat$month<-sapply(strsplit(spdat$dates,"-"),"["*,2*)
> spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",*3*)"
>
> B. Here, I need to define the no. of months, and years separately, right?
> or else what 2, and 3 (in bold) indicates?
>

To get the grouping variable of sequential months that you want, you only
need the month and year values of the dates in the first column. First I
used the "strsplit" function to split the date field at the hyphens, then
used "sapply" to extract ("[") the second (month) and *third (year)* parts
as two new columns. Because you have more than one year of data, you need
the year values or you will group all Januarys, all Februarys and so on.
Notice how I pass both of the new columns as a list (a data frame is a type
of list) in the call to get the mean of each month.

1. Here, as per my understanding, the "3" indicates the 3rd year, right?
But, you showed an average for 2 months of the same year. Then, what "3" in
the  spdat$year object indicate?


C. From this part, I got the exact average values of both January and
> February of 1994 for country A, and B. But, in code, I have a query that I
> need to define  spdat$returnA, and  spdat$returnB separately before writing
> this code, right? Like this, I need to define for each 84 countries
> separately with their respective number of months, and years before writing
> this code, right?
>

I don't think so. Because I don't know what your data looks like, I am
guessing that for each row, it has columns for each of the 84 countries. I
don't know what these columns are named, either. Maybe:

date Australia   Belarus   ...Zambia
01/01/1994   20 21 22
...

Here, due to my misunderstanding about the code, I was wrong. But, what
data structure you guessed, it is absolutely right that for each row, I
have columns for each of the 84 countries. So, I think, I need to define
the date column with no. of months, and years once for all the countries.
Therefore, I got my answer to the first and third question in the previous
email (what you suggested) that I no need to define the column of each
country, as the date, and no. of observations are same for all countries.
But, the no. of days are different for each month, and similarly, for each
year. So, I think I need to define date for each year separately.  Hence, I
have given an example of 12 months, for 2 years (i.e. 1994, and 1995), and
have written the following code. Please correct me in case I am wrong.

 spdat<-data.frame(

dates=paste(c(1:21,1:20,1:23,1:21,1:22,1:22,1:21,1:23,1:22,1:21,1:22,1:22),c(rep(1,21),rep(2,20),
rep(3,23), rep(4,21),
rep(5,22),rep(6,22),rep(7,21),rep(8,23),rep(9,22),rep(10,21),rep(11,22),rep(12,22)
),rep(1994,260)
 dates1=
paste(c(1:22,1:20,1:23,1:20,1:23,1:22,1:21,1:23,1:21,1:22,1:22,1:21),c(rep(1,22),rep(2,20),
rep(3,23), rep(4,20),
rep(5,23),rep(6,22),rep(7,21),rep(8,23),rep(9,21),rep(10,21),rep(11,22),rep(12,21)
),rep(1995,259) ,sep="-")

Concerning the exporting of structure of the dataset to excel, I will have
12*84 matrix. But, please suggest me the way to proceed for the large
sample. I have mentioned below what I understood from your code. Please
correct me if I am wrong.
1. I need to define the date for each year as the no. of days in each month
are different for each year (as mentioned in my above code). For instance,
in my data file, Jan 1994 has 21 days while Jan 1995 has 22 days.
2. Need to define the date column as character.
3. Need to define the monthly average for each month, and year. So, now
code will be as follows.
spdat$month<-sapply(strsplit(spdat$dates,"-"),"[",2,3,4,5,6,7,8,9,10,11,12)
  As I need all months average sequentially.
spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",3)

Here, this meaning of "3", I am really unable to get.

4. Need to define each country with each month and year as mentioned in the
last part of your code.

Please suggest me in this regard.

Thank you.







[image: Mailtrack]

Sender
notified by
Mailtrack

09/13/19,
06:41:41 PM

On Fri, Sep 13, 2019 at 4:24 PM Jim Lemon  wrote:

> Hi Subhamitra,
> I'll try to write my answers adjacent to your questions below.
>
> On Fri, Sep 13, 2019 at 6:08 PM Subhamitra Patra <
> subhamitra.pa...@gmail.com> wrote:
>
>> Dear Sir,
>>
>> Thank you very much for your suggestion.
>>
>> Yes, your suggested code worked. But, actually, I have data from 3rd
>> January 1994 to 3rd August 2017 for very large (i.e. for 84 countries)
>> sample. From this, I have given the example of the years up to 2000. Before
>> applying the same code for the long 24 years, I want to lea

Re: [R] A question on regular expression

2019-09-13 Thread Christofer Bogaso
A quick question.

Could you please explain the -- [^}]* -- part in finding the pattern?

On Fri, Sep 13, 2019 at 12:19 AM Bert Gunter  wrote:
>
>
> You can't use the same regex for str_extract_all as I used for sub (or gsub, 
> which is what is required here)! If you do this sort of thing a lot, you 
> *must* learn more about regex's.
>
> Anyway, this will do what you want I think:
>
> z <- paste("ab{cd$ }ed", "ab{cad$ }ed", collapse = " ")  ## just for 
> readability
>
> > str_extract_all(z,"\\{[^}]*\\}")
> [[1]]
> [1] "{cd$ }"  "{cad$ }"
>
> Cheers,
> Bert
>
> On Thu, Sep 12, 2019 at 10:12 AM Christofer Bogaso 
>  wrote:
>>
>> Thanks Bert,
>>
>> This works, but if in my text there are more than one patterns then
>> fails to generate desired result.
>>
>> library(stringr)
>> str_extract_all(paste("ab{cd$ }ed", "ab{cad$ }ed", collapse = " "),
>> ".*(\\{.*\\}).*")
>>
>> This generates below -
>>
>> [[1]]
>>
>> [1] "ab{cd$ }ed ab{cad$ }ed"
>>
>> I was expecting I would get a vector of length 2 with desired pattern.
>>
>> Where did I make any mistake?
>>
>> Thanks,
>>
>> On Thu, Sep 12, 2019 at 10:29 PM Bert Gunter  wrote:
>> >
>> > > sub(".*(\\{.*\\}).*", "\\1","ab{cd$ }ed")
>> > [1] "{cd$ }"
>> >
>> > Use ".+" instead of ".*" within the {} if you don't want to return empty 
>> > {}'s.
>> >
>> > You might wish to use the stringr package for string matching and 
>> > manipulation, as it provides a more user friendly and consistent interface 
>> > to these tasks.
>> >
>> >
>> > Bert Gunter
>> >
>> > "The trouble with having an open mind is that people keep coming along and 
>> > sticking things into it."
>> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> >
>> >
>> > On Thu, Sep 12, 2019 at 9:31 AM Christofer Bogaso 
>> >  wrote:
>> >>
>> >> Hi,
>> >>
>> >> I am wondering on what is the correct way to select a pattern which goes 
>> >> as -
>> >>
>> >> {"(any character with any length)"}
>> >>
>> >> The expressions " {" " and " "} " both are included in the pattern.
>> >>
>> >> For example, the lookup of the above pattern in the text "
>> >> {"asaf455%"}57573blabla " will result in {"asaf455%"}
>> >>
>> >> Any help will be highly appreciated.
>> >>
>> >> Thanks,
>> >>
>> >> __
>> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Query about calculating the monthly average of daily data columns

2019-09-13 Thread Jim Lemon
Hi Subhamitra,
I'll try to write my answers adjacent to your questions below.

On Fri, Sep 13, 2019 at 6:08 PM Subhamitra Patra 
wrote:

> Dear Sir,
>
> Thank you very much for your suggestion.
>
> Yes, your suggested code worked. But, actually, I have data from 3rd
> January 1994 to 3rd August 2017 for very large (i.e. for 84 countries)
> sample. From this, I have given the example of the years up to 2000. Before
> applying the same code for the long 24 years, I want to learn the logic
> behind the code. Actually, some part of the code is not understandable to
> me which I mentioned in the bold letter as follows.
>
> "spdat<-data.frame(
>   dates=paste(c(1:30,1:28),c(rep(1,30),rep(2,28)),rep(1994,58),sep="-"),
>   returnA=sample(*15:50*,58,TRUE),returnB=sample(*10:45*,58,TRUE))"
>
> A. Here, I need to define the no. of days in a month, and the no. of
> countries name separately, right? But, what is meant by 15:50, and 10:45 in
> return A, and B respectively?
>

To paraphrase Donald Trump, this is FAKE DATA! I have no idea what the real
values of return are, so I made them up using the "sample" function.
However, this is not meant to mislead anyone, just to show how whatever
numbers are in your data can be used in calculations. The colon (":")
operator creates a sequence of numbers starting with the one to the left
and ending with the one to the right.

>
> "# if you only have to get the monthly averages, it can be done this way
> spdat$month<-sapply(strsplit(spdat$dates,"-"),"["*,2*)
> spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",*3*)"
>
> B. Here, I need to define the no. of months, and years separately, right?
> or else what 2, and 3 (in bold) indicates?
>

To get the grouping variable of sequential months that you want, you only
need the month and year values of the dates in the first column. First I
used the "strsplit" function to split the date field at the hyphens, then
used "sapply" to extract ("[") the second (month) and third (year) parts as
two new columns. Because you have more than one year of data, you need the
year values or you will group all Januarys, all Februarys and so on. Notice
how I pass both of the new columns as a list (a data frame is a type of
list) in the call to get the mean of each month.

>
> "# get the averages by month and year - is this correct?
> monthlyA<-by(*spdat$returnA*,spdat[,c("month","year")],mean)
> monthlyB<-by(*spdat$returnB*,spdat[,c("month","year")],mean)"
>
> C. From this part, I got the exact average values of both January and
> February of 1994 for country A, and B. But, in code, I have a query that I
> need to define  spdat$returnA, and  spdat$returnB separately before writing
> this code, right? Like this, I need to define for each 84 countries
> separately with their respective number of months, and years before writing
> this code, right?
>

I don't think so. Because I don't know what your data looks like, I am
guessing that for each row, it has columns for each of the 84 countries. I
don't know what these columns are named, either. Maybe:

date Australia   Belarus   ...Zambia
01/01/1994   20 21 22
...


> Yes, after obtaining the monthly average for each country's data, I need
> to use them for further calculations. So, I want to export the result to
> excel. But, until understanding the code, I think I willn't able to apply
> for the entire sample, and cannot be able to discuss the format of the
> resulted column to export to excel.
>

Say that we perform the grouped mean calculation for the first two country
columns like this:
monmeans<-sapply(spdat[,2:3],by,spdat[,c("month","year")],mean)
monmeans
Australia  Belarus
[1,]  29.7 30.4
[2,]  34.17857 27.39286

We are presented with a 2x2 matrix of monthly means in just the format
someone might use for importing into Excel. The first row is January 1994,
the second February 1994 and so on. By expanding the columns to include all
the countries in your data, You should have the result you want.

Jim

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Query about calculating the monthly average of daily data columns

2019-09-13 Thread PIKAL Petr
Hi

I may be completely wrong but reshape/aggregate should by what you want
spdat
   dates returnA returnB
1   1-1-1994  16  13
2   2-1-1994  44  10
3   3-1-1994  24  32
.
> library(reshape2)
> spdat.m <- melt(spdat)
Using dates as id variables
> str(spdat.m)
'data.frame':   116 obs. of  3 variables:
 $ dates   : Factor w/ 58 levels "1-1-1994","1-2-1994",..: 1 23 44 47 49 51 53 
55 57 3 ...
 $ variable: Factor w/ 2 levels "returnA","returnB": 1 1 1 1 1 1 1 1 1 1 ...
 $ value   : int  16 44 24 47 16 35 34 34 26 36 ...
> spdat.m$realdate <- as.Date(spdat.m[,1], format="%d-%m-%Y")
> aggregate(spdat.m$value, list(format(spdat.m$realdate, "%m.%Y"), 
> spdat.m$variable), mean)
  Group.1 Group.2x
1 01.1994 returnA 31.9
2 02.1994 returnA 32.39286
3 01.1994 returnB 24.26667
4 02.1994 returnB 30.03571

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Subhamitra
> Patra
> Sent: Friday, September 13, 2019 10:08 AM
> To: Jim Lemon 
> Cc: r-help mailing list 
> Subject: Re: [R] Query about calculating the monthly average of daily data
> columns
>
> Dear Sir,
>
> Thank you very much for your suggestion.
>
> Yes, your suggested code worked. But, actually, I have data from 3rd January
> 1994 to 3rd August 2017 for very large (i.e. for 84 countries) sample. From
> this, I have given the example of the years up to 2000. Before applying the
> same code for the long 24 years, I want to learn the logic behind the code.
> Actually, some part of the code is not understandable to me which I
> mentioned in the bold letter as follows.
>
> "spdat<-data.frame(
>   dates=paste(c(1:30,1:28),c(rep(1,30),rep(2,28)),rep(1994,58),sep="-"),
>   returnA=sample(*15:50*,58,TRUE),returnB=sample(*10:45*,58,TRUE))"
>
> A. Here, I need to define the no. of days in a month, and the no. of countries
> name separately, right? But, what is meant by 15:50, and 10:45 in return A,
> and B respectively?
>
> "# if you only have to get the monthly averages, it can be done this way
> spdat$month<-sapply(strsplit(spdat$dates,"-"),"["*,2*)
> spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",*3*)"
>
> B. Here, I need to define the no. of months, and years separately, right?
> or else what 2, and 3 (in bold) indicates?
>
> "# get the averages by month and year - is this correct?
> monthlyA<-by(*spdat$returnA*,spdat[,c("month","year")],mean)
> monthlyB<-by(*spdat$returnB*,spdat[,c("month","year")],mean)"
>
> C. From this part, I got the exact average values of both January and
> February of 1994 for country A, and B. But, in code, I have a query that I
> need to define  spdat$returnA, and  spdat$returnB separately before writing
> this code, right? Like this, I need to define for each 84 countries separately
> with their respective number of months, and years before writing this code,
> right?
>
> Yes, after obtaining the monthly average for each country's data, I need to
> use them for further calculations. So, I want to export the result to excel. 
> But,
> until understanding the code, I think I willn't able to apply for the entire
> sample, and cannot be able to discuss the format of the resulted column to
> export to excel.
>
> Therefore, kindly help me to understand the code.
>
> Thank you very much, Sir, and thanks to this R forum for helping the R-
> beginners.
>
>
>
> [image: Mailtrack]
>  mpaign=signaturevirality5&>
> Sender
> notified by
> Mailtrack
>  mpaign=signaturevirality5&>
> 09/13/19,
> 12:57:58 PM
>
> On Fri, Sep 13, 2019 at 3:15 AM Jim Lemon  wrote:
>
> > Hi Subhamitra,
> > Your data didn't make it through, so I guess the first thing is to
> > guess what it looks like. Here's a try at just January and February of
> > 1994 so that we can see the result on the screen. The logic will work
> > just as well for the whole seven years.
> >
> > # create fake data for the first two months spdat<-data.frame(
> > dates=paste(c(1:30,1:28),c(rep(1,30),rep(2,28)),rep(1994,58),sep="-"),
> >  returnA=sample(15:50,58,TRUE),returnB=sample(10:45,58,TRUE))
> > # I'll assume that the dates in your file are character, not factor
> > spdat$dates<-as.character(spdat$dates)
> > # if you only have to get the monthly averages, it can be done this
> > way
> > spdat$month<-sapply(strsplit(spdat$dates,"-"),"[",2)
> > spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",3)
> > # get the averages by month and year - is this correct?
> > monthlyA<-by(spdat$returnA,spdat[,c("month","year")],mean)
> > monthlyB<-by(spdat$returnB,spdat[,c("month","year")],mean)
> >
> > Now you have what you say you want:
> >
> > monthlyA
> > month: 1
> > year: 1994
> > [1] 34.1
> > 
> > month: 2
> > year: 1994
> > [1] 33.32143
> >
> > monthlyB
> > month: 1
> > year: 1994
> > [1] 29.7
> > --

Re: [R] test if something was plotted on pdf device

2019-09-13 Thread PIKAL Petr
Dear Duncan

Thank you for the code, I will test it or at least check what it does. I 
finally found probably easier solution.

I stay with my original code

if (dev.cur()==1) plot(ecdf(velik[,"ecd"]), main = ufil[j], col=i) else
plot(ecdf(velik[,"ecd"]), add=T, col=i)

After plot is finished and cycle ends, I copy result to pdf device

dev.copy(pdf,paste(gsub(".xls", "", ufil)[j], ".pdf", sep=""))
dev.off()

Using this approach I could stay with my original code (almost), check if plot 
was initialised by dev.cur() and save it after it is finished to pdf.

The only obstacle is that my code flashes during plotting to basic device, 
however I can live with it.

Thank you again and best regards

Petr

> -Original Message-
> From: Duncan Murdoch 
> Sent: Thursday, September 12, 2019 2:29 PM
> To: PIKAL Petr ; r-help mailing list  project.org>
> Subject: Re: [R] test if something was plotted on pdf device
>
> On 12/09/2019 7:10 a.m., PIKAL Petr wrote:
> > Dear all
> >
> > Is there any simple way checking whether after calling pdf device
> something was plotted into it?
> >
> > In interactive session I used
> >
> > if (dev.cur()==1) plot(ecdf(rnorm(100))) else plot(ecdf(rnorm(100)),
> > add=T, col=i) which enabled me to test if plot is open
> >
> > But when I want to call eg. pdf("test.pdf") before cycle
> > dev.cur()==1 is FALSE even when no plot is drawn and plot.new error
> comes.
> >
> >> pdf("test.pdf")
> >
> > if (dev.cur()==1) plot(ecdf(rnorm(100))) else plot(ecdf(rnorm(100)),
> > add=T, col=i)
> >
> > Error in segments(ti.l, y, ti.r, y, col = col.hor, lty = lty, lwd = lwd,  :
> >plot.new has not been called yet
> >
>
> I don't know if this is reliable or not, but you could use code like this:
>
>f <- tempfile()
>pdf(f)
>blankPlot <- recordPlot()
>dev.off()
>unlink(f)
>
>pdf("test.pdf")
>
>...  unknown operations ...
>
>if (dev.cur() == 1 || identical(recordPlot(), blankPlot))
>  plot(ecdf(rnorm(100)))
>else
>  plot(ecdf(rnorm(100)), add=TRUE, col=i)
>
>
>
> Duncan Murdoch
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Bug (?): file.copy() erases 'from' file if the "to" file already exists and is a symlinked file

2019-09-13 Thread Marc Girondot via R-help
If file.copy() is used to replace a symlinked file, it erases the 
original file and does not copy the file. The original file is lost.


> version
 _
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status Patched
major?? 3
minor?? 6.1
year 2019
month?? 09
day?? 06
svn rev?? 77160
language R
version.string R version 3.6.1 Patched (2019-09-06 r77160)
nickname Action of the Toes

#

Here is a reproducible example:

A <- 10
save(A, file="A.Rdata")
file.symlink(from="A.Rdata", to="B.Rdata")
rm(A)

load(file="B.Rdata")
print(A)?? # Perfect

system("ls -l")
## -rw-r--r--?? 1 marcgirondot?? staff?? 70 13 sep 11:44 A.Rdata
## lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:44 B.Rdata -> 
A.Rdata

file.copy(from="A.Rdata", to="B.Rdata", overwrite = TRUE)

system("ls -l")
## -rw-r--r--?? 1 marcgirondot?? staff 0 13 sep 11:44 A.Rdata
## lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:44 B.Rdata -> 
A.Rdata

###

A.Rdata becomes empty: 0B
The content of A.Rdata is lost


In terminal the problem does not occur


marcgirondot$ ls
A.Rdata
marcgirondot$ ln -s A.Rdata B.Rdata
marcgirondot$ ls -l
-rw-r--r--?? 1 marcgirondot?? staff?? 70 13 sep 11:38 A.Rdata
lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:38 B.Rdata -> 
A.Rdata
marcgirondot$ cp A.Rdata B.Rdata
cp: B.Rdata and A.Rdata are identical (not copied).

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Query about calculating the monthly average of daily data columns

2019-09-13 Thread Subhamitra Patra
Dear Sir,

Thank you very much for your suggestion.

Yes, your suggested code worked. But, actually, I have data from 3rd
January 1994 to 3rd August 2017 for very large (i.e. for 84 countries)
sample. From this, I have given the example of the years up to 2000. Before
applying the same code for the long 24 years, I want to learn the logic
behind the code. Actually, some part of the code is not understandable to
me which I mentioned in the bold letter as follows.

"spdat<-data.frame(
  dates=paste(c(1:30,1:28),c(rep(1,30),rep(2,28)),rep(1994,58),sep="-"),
  returnA=sample(*15:50*,58,TRUE),returnB=sample(*10:45*,58,TRUE))"

A. Here, I need to define the no. of days in a month, and the no. of
countries name separately, right? But, what is meant by 15:50, and 10:45 in
return A, and B respectively?

"# if you only have to get the monthly averages, it can be done this way
spdat$month<-sapply(strsplit(spdat$dates,"-"),"["*,2*)
spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",*3*)"

B. Here, I need to define the no. of months, and years separately, right?
or else what 2, and 3 (in bold) indicates?

"# get the averages by month and year - is this correct?
monthlyA<-by(*spdat$returnA*,spdat[,c("month","year")],mean)
monthlyB<-by(*spdat$returnB*,spdat[,c("month","year")],mean)"

C. From this part, I got the exact average values of both January and
February of 1994 for country A, and B. But, in code, I have a query that I
need to define  spdat$returnA, and  spdat$returnB separately before writing
this code, right? Like this, I need to define for each 84 countries
separately with their respective number of months, and years before writing
this code, right?

Yes, after obtaining the monthly average for each country's data, I need to
use them for further calculations. So, I want to export the result to
excel. But, until understanding the code, I think I willn't able to apply
for the entire sample, and cannot be able to discuss the format of the
resulted column to export to excel.

Therefore, kindly help me to understand the code.

Thank you very much, Sir, and thanks to this R forum for helping the
R-beginners.



[image: Mailtrack]

Sender
notified by
Mailtrack

09/13/19,
12:57:58 PM

On Fri, Sep 13, 2019 at 3:15 AM Jim Lemon  wrote:

> Hi Subhamitra,
> Your data didn't make it through, so I guess the first thing is to
> guess what it looks like. Here's a try at just January and February of
> 1994 so that we can see the result on the screen. The logic will work
> just as well for the whole seven years.
>
> # create fake data for the first two months
> spdat<-data.frame(
>  dates=paste(c(1:30,1:28),c(rep(1,30),rep(2,28)),rep(1994,58),sep="-"),
>  returnA=sample(15:50,58,TRUE),returnB=sample(10:45,58,TRUE))
> # I'll assume that the dates in your file are character, not factor
> spdat$dates<-as.character(spdat$dates)
> # if you only have to get the monthly averages, it can be done this way
> spdat$month<-sapply(strsplit(spdat$dates,"-"),"[",2)
> spdat$year<-sapply(strsplit(spdat$dates,"-"),"[",3)
> # get the averages by month and year - is this correct?
> monthlyA<-by(spdat$returnA,spdat[,c("month","year")],mean)
> monthlyB<-by(spdat$returnB,spdat[,c("month","year")],mean)
>
> Now you have what you say you want:
>
> monthlyA
> month: 1
> year: 1994
> [1] 34.1
> 
> month: 2
> year: 1994
> [1] 33.32143
>
> monthlyB
> month: 1
> year: 1994
> [1] 29.7
> 
> month: 2
> year: 1994
> [1] 27.28571
>
> Sorry I didn't use a loop (for(month in 1:12) ... for (year in
> 1994:2000) ...), too lazy.
> Now you have to let us know how this information is to be formatted to
> go into Excel. Excel will import the text as above, but I think you
> want something that you can use for further calculations.
>
> Jim
>
> On Fri, Sep 13, 2019 at 12:54 AM Subhamitra Patra
>  wrote:
> >
> > Dear R-users,
> >
> > I have daily data from 03-01-1994 to 29-12-2000. In my datafile, he first
> > column is date and the second and third columns are the returns of the
> > country A, and B. Here, the date column is same for both countries. I
> want
> > to calculate the monthly average of both country's returns by using a
> loop,
> > and then, I want to export the results into excel.
> >
> > Please help me in this regard.
> >
> > Please find the attached datasheet.
> >
> > Thank you.
> >
> > --
> > *Best Regards,*
> > *Subhamitra Patra*
> > *Phd. Research Scholar*
> > *Department of Humanities and Social Sciences*
> > *Indian Institute of Technology, Kharagpur*
> > *INDIA*
> >
> > [image: Mailtrack]
> > <
> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&;
> >
> > Sender
> > notified by
> > Mailtrack
> > <
> https://mail