Re: [R] [R studio] Plotting of line chart for each columns at 1 page

2018-12-15 Thread Subhamitra Patra
Thank you very much sir. Actually, I excluded all the non-trading days.
Therefore, Each year will have 226 observations and total 6154 observations
for each column. The data which I plotted is not rough data. I obtained the
rolling observations of window 500 from my original data. So, the no. of
observations for each resulted column is (6154-500)+1=5655. So, It is not
accurate as per the days of calculations of each year.

Ok, Sir, I will go through your suggestion, obtain the results for each
column of my data and would like to discuss the results with you. After
solving of this problem, I would like to discuss another 2 queries.

Thank you very much Sir for educating a new R learner.

[image: Mailtrack]

Sender
notified by
Mailtrack

12/16/18,
12:20:17 PM

On Sun, Dec 16, 2018 at 8:10 AM Jim Lemon  wrote:

> Hi Subhamitra,
> Thanks. Now I can provide some assistance instead of just complaining.
> Your first problem is the temporal extent of the data. There are 8613 days
> and 6512 weekdays between the two dates you list, but only 5655
> observations in your data. Therefore it is unlikely that you have a
> complete data series, or perhaps you have the wrong dates. For the moment
> I'll assume that there are missing observations. What I am going to do is
> to match the 24 years (1994-2017) to their approximate positions in the
> time series. This will give you the x-axis labels that you want, close
> enough for this illustration. I doubt that you will need anything more
> accurate. You have a span of 24.58 years, which means that if your missing
> observations are uniformly distributed, you will have almost exactly 226
> observations per year. When i tried this, I got too many intervals, so I
> increased the increment to 229 and that worked. To get the positions for
> the middle of each year in the indices of the data:
>
> year_mids<-seq(182,5655,by=229)
>
> Now I suppress the x-axis by adding xaxt="n" to each call to plot. Then I
> add a command to display the years at the positions I have calculated:
>
> axis(1,at=year_mids,labels=1994:2017)
>
> Also note that I have added braces to the "for" loop. Putting it all
> together:
>
> year_mids<-seq(182,5655,by=229)
> pdf("EMs.pdf",width=20,height=20)
> par(mfrow=c(5,4))
> # import your first sheet here (16 columns)
> EMs1.1<-read.csv("EMs1.1.csv")
> ncolumns<-ncol(EMs1.1)
> for(i in 1:ncolumns) {
>   plot(EMs1.1[,i],type="l",col = "Red", xlab="Time",
>ylab="APEn", main=names(EMs1.1)[i],xaxt="n")
>  axis(1,at=year_mids,labels=1994:2017)
> }
> #import your second sheet here, (1 column)
> EMs2.1<-read.csv("EMs2.1.csv")
> ncolumns<-ncol(EMs2.1)
> for(i in 1:ncolumns) {
>   plot(EMs2.1[,i],type="l",col = "Red", xlab="Time",
>ylab="APEn", main=names(EMs2.1)[i],xaxt="n")
>  axis(1,at=year_mids,labels=1994:2017)
> }
> # import your Third sheet here, (1 column)
> EMs3.1<-read.csv("EMs3.1.csv")
> ncolumns<-ncol(EMs3.1)
> for(i in 1:ncolumns) {
>   plot(EMs3.1[,i],type="l",col = "Red", xlab="Time",
>ylab="APEn", main=names(EMs3.1)[i],xaxt="n")
>  axis(1,at=year_mids,labels=1994:2017)
> }
> # import your fourth sheet here, (1 column)
> EMs4.1<-read.csv("EMs4.1.csv")
> ncolumns<-ncol(EMs4.1)
> for(i in 1:ncolumns) {
>   plot(EMs4.1[,i],type="l",col = "Red", xlab="Time",
>ylab="APEn", main=names(EMs4.1)[i],xaxt="n")
>  axis(1,at=year_mids,labels=1994:2017)
> }
> # finish plotting
> dev.off()
>
> With any luck, you are now okay. Remember, this is a hack to deal with
> data that are not what you think they are.
>
> Jim
>
>

-- 
*Best Regards,*
*Subhamitra Patra*
*Phd. Research Scholar*
*Department of Humanities and Social Sciences*
*Indian Institute of Technology, Kharagpur*
*INDIA*

[[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] Combine lists into a data frame or append them to a text file

2018-12-15 Thread Jim Lemon
Hi Ek,
I thought there would be a simple fix for this, but had to write a
little function:

fillList<-function(x) {
 maxrows<-max(unlist(lapply(x,length)))
 return(lapply(x,"[",1:maxrows))
}

that fills up the rows of each list with NAs. I got the expected result with:

testlist<-list(a=1:8,b=1:9,c=1:10)
as.data.frame(fillList(testlist))

so:

for (i in 1:length(MyTables)) {
write.table(as.data.frame(fillList(MyTables[i])),
 file = "Temp.txt",append = TRUE,quote = TRUE)

may do the job.

Jim

On Sun, Dec 16, 2018 at 2:28 PM Ek Esawi  wrote:
>
> Hi All,
>
> I have an R object that is made up of N number of lists which are all
> of different number of columns and rows.  I want to combine the N
> lists into a single data frame or write (append) them into text file.
> I hope the question is clear and doesn’t require an example. I am
> hoping to accomplish this using base R functions.
> Below is what I tried but both gave me the same error which I do
> understand, I think, but I don’t know how to fix it. My R object is
> MyTables
>
> lapply(MyTables, function(x) write.table(x, file = "Temp.txt",append = TRUE ))
> OR
> for (i in 1:length(MyTables)) {
> write.table(MyTables[i], file = "Temp.txt",append = TRUE,quote = TRUE)
>
> the error
> Error in (function (..., row.names = NULL, check.rows = FALSE,
> check.names = TRUE,  :
>   arguments imply differing number of rows: 51, 8, 30
>
> Thanks--EK
>
> __
> 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] Combine lists into a data frame or append them to a text file

2018-12-15 Thread Bert Gunter
FWIW, I had no trouble writing a test case to a file with either version of
your code. As we have no idea what your data look like, I don't know how
anyone can diagnose the problem. But maybe I'm wrong and someone else will
recognize the issue.

Cheers,
Bert

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 Sat, Dec 15, 2018 at 7:28 PM Ek Esawi  wrote:

> Hi All,
>
> I have an R object that is made up of N number of lists which are all
> of different number of columns and rows.  I want to combine the N
> lists into a single data frame or write (append) them into text file.
> I hope the question is clear and doesn’t require an example. I am
> hoping to accomplish this using base R functions.
> Below is what I tried but both gave me the same error which I do
> understand, I think, but I don’t know how to fix it. My R object is
> MyTables
>
> lapply(MyTables, function(x) write.table(x, file = "Temp.txt",append =
> TRUE ))
> OR
> for (i in 1:length(MyTables)) {
> write.table(MyTables[i], file = "Temp.txt",append = TRUE,quote = TRUE)
>
> the error
> Error in (function (..., row.names = NULL, check.rows = FALSE,
> check.names = TRUE,  :
>   arguments imply differing number of rows: 51, 8, 30
>
> Thanks--EK
>
> __
> 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.
>

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


[R] Combine lists into a data frame or append them to a text file

2018-12-15 Thread Ek Esawi
Hi All,

I have an R object that is made up of N number of lists which are all
of different number of columns and rows.  I want to combine the N
lists into a single data frame or write (append) them into text file.
I hope the question is clear and doesn’t require an example. I am
hoping to accomplish this using base R functions.
Below is what I tried but both gave me the same error which I do
understand, I think, but I don’t know how to fix it. My R object is
MyTables

lapply(MyTables, function(x) write.table(x, file = "Temp.txt",append = TRUE ))
OR
for (i in 1:length(MyTables)) {
write.table(MyTables[i], file = "Temp.txt",append = TRUE,quote = TRUE)

the error
Error in (function (..., row.names = NULL, check.rows = FALSE,
check.names = TRUE,  :
  arguments imply differing number of rows: 51, 8, 30

Thanks--EK

__
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] [R studio] Plotting of line chart for each columns at 1 page

2018-12-15 Thread Jim Lemon
Hi Subhamitra,
Thanks. Now I can provide some assistance instead of just complaining. Your
first problem is the temporal extent of the data. There are 8613 days and
6512 weekdays between the two dates you list, but only 5655 observations in
your data. Therefore it is unlikely that you have a complete data series,
or perhaps you have the wrong dates. For the moment I'll assume that there
are missing observations. What I am going to do is to match the 24 years
(1994-2017) to their approximate positions in the time series. This will
give you the x-axis labels that you want, close enough for this
illustration. I doubt that you will need anything more accurate. You have a
span of 24.58 years, which means that if your missing observations are
uniformly distributed, you will have almost exactly 226 observations per
year. When i tried this, I got too many intervals, so I increased the
increment to 229 and that worked. To get the positions for the middle of
each year in the indices of the data:

year_mids<-seq(182,5655,by=229)

Now I suppress the x-axis by adding xaxt="n" to each call to plot. Then I
add a command to display the years at the positions I have calculated:

axis(1,at=year_mids,labels=1994:2017)

Also note that I have added braces to the "for" loop. Putting it all
together:

year_mids<-seq(182,5655,by=229)
pdf("EMs.pdf",width=20,height=20)
par(mfrow=c(5,4))
# import your first sheet here (16 columns)
EMs1.1<-read.csv("EMs1.1.csv")
ncolumns<-ncol(EMs1.1)
for(i in 1:ncolumns) {
  plot(EMs1.1[,i],type="l",col = "Red", xlab="Time",
   ylab="APEn", main=names(EMs1.1)[i],xaxt="n")
 axis(1,at=year_mids,labels=1994:2017)
}
#import your second sheet here, (1 column)
EMs2.1<-read.csv("EMs2.1.csv")
ncolumns<-ncol(EMs2.1)
for(i in 1:ncolumns) {
  plot(EMs2.1[,i],type="l",col = "Red", xlab="Time",
   ylab="APEn", main=names(EMs2.1)[i],xaxt="n")
 axis(1,at=year_mids,labels=1994:2017)
}
# import your Third sheet here, (1 column)
EMs3.1<-read.csv("EMs3.1.csv")
ncolumns<-ncol(EMs3.1)
for(i in 1:ncolumns) {
  plot(EMs3.1[,i],type="l",col = "Red", xlab="Time",
   ylab="APEn", main=names(EMs3.1)[i],xaxt="n")
 axis(1,at=year_mids,labels=1994:2017)
}
# import your fourth sheet here, (1 column)
EMs4.1<-read.csv("EMs4.1.csv")
ncolumns<-ncol(EMs4.1)
for(i in 1:ncolumns) {
  plot(EMs4.1[,i],type="l",col = "Red", xlab="Time",
   ylab="APEn", main=names(EMs4.1)[i],xaxt="n")
 axis(1,at=year_mids,labels=1994:2017)
}
# finish plotting
dev.off()

With any luck, you are now okay. Remember, this is a hack to deal with data
that are not what you think they are.

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] Dealing with special characters at end of line in file

2018-12-15 Thread J C Nash
Many thanks. I'd misread the doc re fixed, and misunderstood the number of 
escapes. Sigh.

JN


On 2018-12-15 10:45 a.m., Bert Gunter wrote:
> ... or used the fixed = TRUE argument.
> 
>> z <-"In  Alvarez Cabral street by no. 105.\\000"
> 
>> sub("\\000","", z, fixed = TRUE)
> [1] "In  Alvarez Cabral street by no. 105."
> 
> 
> 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 Sat, Dec 15, 2018 at 7:32 AM J C Nash  > wrote:
> 
> I am trying to fix up some image files (jpg) that have comments in them.
> Unfortunately, many have had extra special characters encoded.
> 
> rdjpgcom, called from an R script, returns a comment e.g.,
> 
> "In  Alvarez Cabral street by no. 105.\\000"
> 
> I want to get rid of "\\000", but sub seems
> to be giving trouble.
> 
> > sub("\\000", "", ctxt)
> [1] "In  Alvarez Cabral street by no. 105.\\0"
> 
> Anyone know how to resolve this?
> 
> JN
> 
> __
> 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] Dealing with special characters at end of line in file

2018-12-15 Thread Bert Gunter
... or used the fixed = TRUE argument.

> z <-"In  Alvarez Cabral street by no. 105.\\000"

> sub("\\000","", z, fixed = TRUE)
[1] "In  Alvarez Cabral street by no. 105."


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 Sat, Dec 15, 2018 at 7:32 AM J C Nash  wrote:

> I am trying to fix up some image files (jpg) that have comments in them.
> Unfortunately, many have had extra special characters encoded.
>
> rdjpgcom, called from an R script, returns a comment e.g.,
>
> "In  Alvarez Cabral street by no. 105.\\000"
>
> I want to get rid of "\\000", but sub seems
> to be giving trouble.
>
> > sub("\\000", "", ctxt)
> [1] "In  Alvarez Cabral street by no. 105.\\0"
>
> Anyone know how to resolve this?
>
> JN
>
> __
> 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.
>

[[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] Dealing with special characters at end of line in file

2018-12-15 Thread David L Carlson
Each of the backslashes need to be escaped with a backslash:

> ctxt <- "In  Alvarez Cabral street by no. 105.\\000"
> sub("000", "", ctxt)
[1] "In  Alvarez Cabral street by no. 105."

---
David L. Carlson
Department of Anthropology
Texas A University

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of J C Nash
Sent: Saturday, December 15, 2018 9:32 AM
To: r-help 
Subject: [R] Dealing with special characters at end of line in file

I am trying to fix up some image files (jpg) that have comments in them.
Unfortunately, many have had extra special characters encoded.

rdjpgcom, called from an R script, returns a comment e.g.,

"In  Alvarez Cabral street by no. 105.\\000"

I want to get rid of "\\000", but sub seems
to be giving trouble.

> sub("\\000", "", ctxt)
[1] "In  Alvarez Cabral street by no. 105.\\0"

Anyone know how to resolve this?

JN

__
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.


[R] Dealing with special characters at end of line in file

2018-12-15 Thread J C Nash
I am trying to fix up some image files (jpg) that have comments in them.
Unfortunately, many have had extra special characters encoded.

rdjpgcom, called from an R script, returns a comment e.g.,

"In  Alvarez Cabral street by no. 105.\\000"

I want to get rid of "\\000", but sub seems
to be giving trouble.

> sub("\\000", "", ctxt)
[1] "In  Alvarez Cabral street by no. 105.\\0"

Anyone know how to resolve this?

JN

__
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] Read text files with Chinese characters

2018-12-15 Thread Patrick Giraudoux
Dear listers,

There is number of requests about reading Chinese characters from Excel 
or text files. I had to cope with the issue and wrote a small manual 
about it. It might not be an optimal solution, but at least it works :-)

One can download the pdf at: 
https://chrono-environnement.univ-fcomte.fr/personnes/annuaire/article/giraudoux-patrick?lang=en#chinese

Cheers,

Patrick



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