Re: [R] iterators : checkFunc with ireadLines

2020-05-23 Thread William Michels via R-help
Hi Laurent,

Seeking to give you an "R-only" solution, I thought the read.fwf()
function might be useful (to read-in your first column of data, only).
However Jeff is correct that this is a poor strategy, since read.fwf()
reads the entire file into R (documented in "Fixed-width-format
files", Section 2.2: R Data Import/Export Manual).

Jeff has suggested a number of packages, as well as using a database.
Ivan Krylov has posted answers using grep, awk and perl (perl5--to
disambiguate). [In point of fact, the R Data Import/Export Manual
suggests using perl]. Similar to Ivan, I've posted code below using
the Raku programming language (the language formerly known as Perl6).
Regexes are claimed to be more readable, but are currently very slow
in Raku. However on the plus side, the language is designed to handle
Unicode gracefully:

> # pipe() using raku-grep on Laurent's data (sep=mult whitespace):
> con_obj1 <- pipe(paste("raku -e '.put for lines.grep( / ^^N053 | ^^N163 /, :p 
> );' ", "Laurents.txt"), open="rt");
> p6_import_a <- scan(file=con_obj1, what=list("","","","","","","","","",""), 
> flush=TRUE, multi.line=FALSE, quiet=TRUE);
> close(con_obj1);
> as.data.frame(sapply(p6_import_a, t), stringsAsFactors=FALSE);
  V1   V2V3V4V5V6V7V8
  V9   V10
1  2 N053 -0.014083 -0.004741  0.001443 -0.010152 -0.012996 -0.005337
-0.008738 -0.015094
2  4 N163 -0.054023 -0.049345 -0.037158  -0.04112 -0.044612 -0.036953
-0.036061 -0.044516
>
> # pipe() using raku-grep "starts-with" to find genbankID ( >3GB TSV file)
> # "lines[0..5]" restricts raku to reading first 6 lines!
> # change "lines[0..5]" to "lines" to run raku code on whole file:
> con_obj2 <- pipe(paste("raku -e '.put for lines[0..5].grep( 
> *.starts-with(q[A00145]), :p);' ", "genbankIDs_3GB.tsv"), "rt");
> p6_import_b <- read.table(con_obj2, sep="\t");
> close(con_obj2)
> p6_import_b
  V1 V2   V3  V4 V5
1  4 A00145 A00145.1 IFN-alpha A NA
>
> # unicode test using R's system() function:
> try(system("raku -ne '.grep( /  你好  |  こんにちは  |  مرحبا  |  Привет  /, :v 
> ).put;'  hello_7lang.txt", intern = TRUE, ignore.stderr = FALSE))
[1] """"""
"你好 Chinese"
[5] "こんにちは Japanese" "مرحبا Arabic""Привет Russian"
>

[special thanks to Brad Gilbert, Joseph Brenner and others on the
perl6-users mailing list. All errors above are my own.]

HTH, Bill.

W. Michels, Ph.D.




On Fri, May 22, 2020 at 4:48 AM Laurent Rhelp  wrote:
>
> Hi Ivan,
>Endeed, it is a good idea. I am under MSwindows but I can use the
> bash command I use with git. I will see how to do that with the unix
> command lines.
>
>
> Le 20/05/2020 à 09:46, Ivan Krylov a écrit :
> > Hi Laurent,
> >
> > I am not saying this will work every time and I do recognise that this
> > is very different from a more general solution that you had envisioned,
> > but if you are on an UNIX-like system or have the relevant utilities
> > installed and on the %PATH% on Windows, you can filter the input file
> > line-by-line using a pipe and an external program:
> >
> > On Sun, 17 May 2020 15:52:30 +0200
> > Laurent Rhelp  wrote:
> >
> >> # sensors to keep
> >> sensors <-  c("N053", "N163")
> > # filter on the beginning of the line
> > i <- pipe("grep -E '^(N053|N163)' test.txt")
> > # or:
> > # filter on the beginning of the given column
> > # (use $2 for the second column, etc.)
> > i <- pipe("awk '($1 ~ \"^(N053|N163)\")' test.txt")
> > # or:
> > # since your message is full of Unicode non-breaking spaces, I have to
> > # bring in heavier machinery to handle those correctly;
> > # only this solution manages to match full column values
> > # (here you can also use $F[1] for second column and so on)
> > i <- pipe("perl -CSD -F'\\s+' -lE \\
> >   'print join qq{\\t}, @F if $F[0] =~ /^(N053|N163)$/' \\
> >   test.txt
> > ")
> > lines <- read.table(i) # closes i when done
> >
> > The downside of this approach is having to shell-escape the command
> > lines, which can become complicated, and choosing between use of regular
> > expressions and more wordy programs (Unicode whitespace in the input
> > doesn't help, either).
> >
>
>
> --
> L'absence de virus dans ce courrier électronique a été vérifiée par le 
> logiciel antivirus Avast.
> https://www.avast.com/antivirus
>
> __
> 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] Wordcloud errors

2020-05-23 Thread Bryan Mac
Hi all,

I am trying to create word clouds using this script but I am getting warnings.

Script:

  if (runtype=="native") {
words <- Corpus(VectorSource(test123b[,2]))
wordcloud(words, min.freq = minfreq, max.words=300, random.order = 
FALSE ,colors=brewer.pal(9,"Reds")[0:-3])

  }   else {
wordcloud((as.character(test123[,2])), min.freq = minfreq, 
max.words=300, random.order = FALSE ,colors=brewer.pal(9,"Reds")[0:-3])

warning messages:
1: in tm_map.simplecorpus(corpus, tm::removepunctuation) : transformation drops 
documents
2: in tm_map.simplecorpus(corpus, function(x) tm::removewords(x, 
tm::stopwords())) : transformation drops documents
3: in tm_map.simplecorpus(corpus, tm::removepunctuation) : transformation drops 
documents
4: in tm_map.simplecorpus(corpus, function(x) tm::removewords(x, 
tm::stopwords())) : transformation drops documents
5: in tm_map.simplecorpus(corpus, tm::removepunctuation) : transformation drops 
documents
6: in tm_map.simplecorpus(corpus, function(x) tm::removewords(x, 
tm::stopwords())) : transformation drops documents


t still produces an output but the warning bugs me. R-help, is there a way to 
fix this script so that there are no warnings??


Thanks,
Bryan

[[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] [External Email] Re: [External] Re: access for free more than 500 essential Springer Nature textbooks

2020-05-23 Thread peter dalgaard
Some of them are generally available. At least they look that way from here

E.g., (shameless plug...)

https://link.springer.com/book/10.1007/978-0-387-79054-1

-pd


> On 23 May 2020, at 06:15 , Christopher W. Ryan  wrote:
> 
> Am I interpreting this offer correctly, that it is for libraries to
> obtain access to the e-books for free? It does not seem to me that an
> invididual can download one--am I missing that part?
> 
> Thanks
> 
> --Chris Ryan
> 
> Mark Leeds wrote:
>> Abby: here's an easier link for seeing what you might like.
>> 
>> https://link.springer.com/search?facet-content-type=%22Book%22&package=mat-covid19_textbooks&%23038;facet-language=%22En%22&%23038;sortOrder=newestFirst&%23038;showAll=true
>> 
>> On Fri, May 22, 2020 at 9:18 PM Richard O'Keefe  wrote:
>> 
>>> the real pleasure comes from things you weren't looking for but recognise
>>> as just what you needed.
>>> 
>>> On Sat, 23 May 2020 at 12:34, Jeff Newmiller 
>>> wrote:
>>> 
 You are bound to be disappointed if you invert the purpose of the list.
 This is marketing... think of it as a sale... stores rarely put their
 entire stock on sale... particularly if the sale price is zero. You have
>>> to
 start with the list and look for interesting titles.
 
 But don't let me dissuade you from adding to your killfile if that seems
 more useful to you.
 
 On May 22, 2020 5:04:29 PM PDT, Abby Spurdle 
>>> wrote:
>> The Excel file is what you need.
> 
> Well, now I'm in a bad mood.
> 
> I went to all the trouble of opening the thing...
> And the first two Springer-published books I look for, aren't there.
> 
> (1) Programming with Data, John Chambers
> (2) Applied Econometrics with R, Z and co.
> 
> Next time someone tells me to use an Excel document, I'm adding them
> to the spam list.
> 
> __
> 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.
 
>>> 
>>>[[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.
>>> 
>> 
>>  [[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-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] Wordcloud warnings

2020-05-23 Thread John Kane
Hi Brian,
i think we may need a bit more information. It looks like you are doing
some text mining; can you tell us what libraries you have loaded and
perhaps provide us with some sample data?
And an example of what you are doing?

See the links below for some suggestions

 http://adv-r.had.co.nz/Reproducibility.html

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example




On Sat, 23 May 2020 at 02:53, Bryan Mac  wrote:

> Hi,
>
> I am having trouble understanding why I am getting this warning and how to
> fix it. I don’t have any of these functions in my script..
>
> This is the warning:
>
> warning messages:
> 1: in tm_map.simplecorpus(corpus, tm::removepunctuation) : transformation
> drops documents
> 2: in tm_map.simplecorpus(corpus, function(x) tm::removewords(x,
> tm::stopwords())) : transformation drops documents
> 3: in tm_map.simplecorpus(corpus, tm::removepunctuation) : transformation
> drops documents
> 4: in tm_map.simplecorpus(corpus, function(x) tm::removewords(x,
> tm::stopwords())) : transformation drops documents
> 5: in tm_map.simplecorpus(corpus, tm::removepunctuation) : transformation
> drops documents
> 6: in tm_map.simplecorpus(corpus, function(x) tm::removewords(x,
> tm::stopwords())) : transformation drops documents
>
>
> This is the script:
>
>  if (runtype=="native") {
> words <- Corpus(VectorSource(test123b[,2]))
> wordcloud(words, min.freq = minfreq, max.words=300, random.order =
> FALSE ,colors=brewer.pal(9,"Reds")[0:-3])
>
>   }   else {
> wordcloud((as.character(test123[,2])), min.freq = minfreq,
> max.words=300, random.order = FALSE ,colors=brewer.pal(9,"Reds")[0:-3])
>
>   }
>
>
> Best,
> Bryan
> __
> 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.
>


-- 
John Kane
Kingston ON Canada

[[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] access for free more than 500 essential Springer Nature textbooks

2020-05-23 Thread Patrick (Malone Quantitative)
Thanks, Rich! I found several books to peruse.

On Fri, May 22, 2020 at 12:29 PM Richard M. Heiberger 
wrote:

> Springer has just made available free access to many books through July.
> This is part of their global program to support educators, students
> and academics
> affected by coronavirus lockdown.
>
> Their list includes about 20 statistics books in English and 2 in
> German.  Several, including mine, have R in the title or subtitle.
>
> This link describes the program:
>
> https://www.springernature.com/gp/librarians/news-events/all-news-articles/industry-news-initiatives/free-access-to-textbooks-for-institutions-affected-by-coronaviru/17855960?sap-outbound-id=07923935E132AFCC90201BAEA7D6755EC6C597DE&utm_source=hybris-campaign&utm_medium=email&utm_campaign=000_BARZ01_001531_AEXS_AWA_CB02_GL_txt_covid&utm_content=EN_internal_5917_20200522&mkt-key=42010A0550671EDA9BA73AC34F576EF6
>
> My book is
> Statistical Analysis and Data Display, Richard M. Heiberger, Burt
> Holland, 2nd ed. 2015
> It is supported by the HH package available from CRAN.
>
> Rich
>
> __
> 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.
>


-- 
Patrick S. Malone, Ph.D., Malone Quantitative
NEW Service Models: http://malonequantitative.com

He/Him/His

[[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] min rows multiplication by the max rows

2020-05-23 Thread Jeff Newmiller
Please post using plain text format... otherwise what we see can be corrupted 
as compared to what you saw.

The obvious solution is:

apply( M, 1, min ) * apply( N, 1, max )

but Google sez there is an optimized version useful with large matrices:

library( Rfast )
rowMins( M ) * rowMins( N )

(untested)

On May 23, 2020 7:30:48 AM PDT, Vahid Borji  wrote:
>Hi my R friends,
>
>I have two matrices as follows:
>
>M<-matrix(c(1,4,1,3,1,4,2,3,1,2,1,2),3)
>
>1322
>4131
>1412
>
>N<-matrix(c(1,1,2,2,3,4,-2,2,1,4,3,-1),3)
>
>12   -24
>1323
>241   -1
>
>I want to find a vector which is a matrix 1*3 and each of its elements
>is
>the multiplication of min element of each row of M by the max element
>of
>the corresponding row of N (for example, the first element of the
>vector is
>the min element of the first row of matrix M, which is 1, multiply by
>the
>max element of the first row of matrix N, which is 4, and so the first
>element of the vector is 1*4 which is 4).
>The final answer is: (1*4, 1*3,1*4)=(4,3,4)
>
>To find this vector (or matrix) I have written the below code:
>c(min(M[1,])*max(N[1,]),min(M[2,])*max(N[2,]),min(M[3,])*max(N[3,]))
>But it is so long. could anyone writes a shorter (or simpler, or
>easier)
>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.

-- 
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] min rows multiplication by the max rows

2020-05-23 Thread Rui Barradas

Hello,

I have just found out that you are cross posting [1].
Please do not cross post, ask a question, wait for an answer and after 
or 3 days, if you don't have a (satisfactory) answer, ask somewhere else.


[1] 
https://stackoverflow.com/questions/61973737/min-rows-multiplication-by-the-max-rows



Rui Barradas

Às 15:52 de 23/05/20, Rui Barradas escreveu:

Hello,

Use ?apply on each of the matrices.


min_max <- function(X, Y, na.rm = FALSE){
   Min <- apply(X, 1, min, na.rm = na.rm)
   Max <- apply(Y, 1, max, na.rm = na.rm)
   Min*Max
}
min_max(M, N)
#[1] 4 3 4


Hope this helps,

Rui Barradas

Às 15:30 de 23/05/20, Vahid Borji escreveu:

Hi my R friends,

I have two matrices as follows:

M<-matrix(c(1,4,1,3,1,4,2,3,1,2,1,2),3)

1    3    2    2
4    1    3    1
1    4    1    2

N<-matrix(c(1,1,2,2,3,4,-2,2,1,4,3,-1),3)

1    2   -2    4
1    3    2    3
2    4    1   -1

I want to find a vector which is a matrix 1*3 and each of its elements is
the multiplication of min element of each row of M by the max element of
the corresponding row of N (for example, the first element of the 
vector is

the min element of the first row of matrix M, which is 1, multiply by the
max element of the first row of matrix N, which is 4, and so the first
element of the vector is 1*4 which is 4).
The final answer is: (1*4, 1*3,1*4)=(4,3,4)

To find this vector (or matrix) I have written the below code:
c(min(M[1,])*max(N[1,]),min(M[2,])*max(N[2,]),min(M[3,])*max(N[3,]))
But it is so long. could anyone writes a shorter (or simpler, or easier)
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-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] min rows multiplication by the max rows

2020-05-23 Thread Rui Barradas

Hello,

Use ?apply on each of the matrices.


min_max <- function(X, Y, na.rm = FALSE){
  Min <- apply(X, 1, min, na.rm = na.rm)
  Max <- apply(Y, 1, max, na.rm = na.rm)
  Min*Max
}
min_max(M, N)
#[1] 4 3 4


Hope this helps,

Rui Barradas

Às 15:30 de 23/05/20, Vahid Borji escreveu:

Hi my R friends,

I have two matrices as follows:

M<-matrix(c(1,4,1,3,1,4,2,3,1,2,1,2),3)

1322
4131
1412

N<-matrix(c(1,1,2,2,3,4,-2,2,1,4,3,-1),3)

12   -24
1323
241   -1

I want to find a vector which is a matrix 1*3 and each of its elements is
the multiplication of min element of each row of M by the max element of
the corresponding row of N (for example, the first element of the vector is
the min element of the first row of matrix M, which is 1, multiply by the
max element of the first row of matrix N, which is 4, and so the first
element of the vector is 1*4 which is 4).
The final answer is: (1*4, 1*3,1*4)=(4,3,4)

To find this vector (or matrix) I have written the below code:
c(min(M[1,])*max(N[1,]),min(M[2,])*max(N[2,]),min(M[3,])*max(N[3,]))
But it is so long. could anyone writes a shorter (or simpler, or easier)
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-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] min rows multiplication by the max rows

2020-05-23 Thread Vahid Borji
Hi my R friends,

I have two matrices as follows:

M<-matrix(c(1,4,1,3,1,4,2,3,1,2,1,2),3)

1322
4131
1412

N<-matrix(c(1,1,2,2,3,4,-2,2,1,4,3,-1),3)

12   -24
1323
241   -1

I want to find a vector which is a matrix 1*3 and each of its elements is
the multiplication of min element of each row of M by the max element of
the corresponding row of N (for example, the first element of the vector is
the min element of the first row of matrix M, which is 1, multiply by the
max element of the first row of matrix N, which is 4, and so the first
element of the vector is 1*4 which is 4).
The final answer is: (1*4, 1*3,1*4)=(4,3,4)

To find this vector (or matrix) I have written the below code:
c(min(M[1,])*max(N[1,]),min(M[2,])*max(N[2,]),min(M[3,])*max(N[3,]))
But it is so long. could anyone writes a shorter (or simpler, or easier)
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] How to make a vector with string elements without space

2020-05-23 Thread Boris Steipe
The c() is unnecessary. paste() returns a vector.

Paste separates elements with " " by default. Set the separator to "" instead.
paste("c",1:10, sep = "")

... or use paste0(), which has "" as default separator.
paste0("c",1:10)

?paste  is your friend.


B.




> On 2020-05-23, at 22:25, Vahid Borji  wrote:
> 
> Hello my r friends,
> I want to make a vector with elements (c1,c2,...,c10).
> I wrote the below code:
> c(paste("c",1:10))
> My code works but it gives me elements like "c 1", "c 2" to "c 10". I mean
> there is a space between each c and its corresponding number. I want the
> elements of the vector to be like "c1", "c2", to "c10"  (without space
> between c and number). How can I fix this problem in my 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-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] How to make a vector with string elements without space

2020-05-23 Thread Vahid Borji
Hello my r friends,
I want to make a vector with elements (c1,c2,...,c10).
I wrote the below code:
c(paste("c",1:10))
My code works but it gives me elements like "c 1", "c 2" to "c 10". I mean
there is a space between each c and its corresponding number. I want the
elements of the vector to be like "c1", "c2", to "c10"  (without space
between c and number). How can I fix this problem in my 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] Bayesian estimation with MCMC

2020-05-23 Thread Ivan Krylov
On Sat, 23 May 2020 14:58:34 +0530
Christofer Bogaso  wrote:

>Any pointer will be highly appreciated.

"Getting help with R" [1] describes several ways of looking for
R-related things. In particular, there is a Bayesian CRAN Task View
[2], which (as of now) has 52 occurrences of "MCMC".

-- 
Best regards,
Ivan

[1] https://www.r-project.org/help.html
[2] https://cran.r-project.org/view=Bayesian

__
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] Bayesian estimation with MCMC

2020-05-23 Thread Eric Berger
Hi Christofer,
Did you try web search? I entered 'R CRAN Bayesian parameter
estimation with MCMC'
and it came back with the following which seems relevant.

https://cran.r-project.org/web/packages/airGR/vignettes/V02.2_param_mcmc.html

There are other search results, such as:
https://cran.r-project.org/web/packages/deBInfer/index.html

You should note that using R does not exclude using pymc3 (or any
other Python package) from R.
The R package reticulate makes it easy to use python packages from an R session.
See https://cran.r-project.org/web/packages/reticulate/index.html

HTH,
Eric

On Sat, May 23, 2020 at 12:29 PM Christofer Bogaso
 wrote:
>
> Hi,
>
> In python there is a package called pymc3 for Bayesian parameter
> estimation with MCMC.
>
> I am curious if there is any equivalent package available for R.
>
> Any pointer will be highly appreciated.
>
> __
> 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] The best way for making speciall matrix

2020-05-23 Thread Rui Barradas

Hello,

Please keep this on the list, R-help is threaded and it becomes part of 
the archives, maybe it will be usefull to others.



You are now asking 2 other different questions.
Are you looking for something like this?

two_values_mat <- function(n, fill = 1, diagonal = 0){
  m <- matrix(fill, nrow = n, ncol = n)
  diag(m) <- diagonal
  m
}
two_values_mat(3)
two_values_mat(3, 0.5, 1)

odd_even_mat <- function(n){
  even <- n %% 2 == 0
  nr <- floor(sqrt(n)) - !even
  nc <- ceiling(n/nr)
  i <- c(0, seq.int(n - even))
  matrix(2*i + !even, nrow = nr, ncol = nc, byrow = TRUE)
}
odd_even_mat(30)
odd_even_mat(17)


Hope this ehlps,

Rui Barradas

Às 11:52 de 23/05/20, Vahid Borji escreveu:

Thank you Rui,
Actually, I am making some matrix as follows:
0 1 1
1 0 1
1 1 0
matrix(rep(c(0,1,1,1),3),nrow=3,ncol=3)
and
1  3   5  7  9  11
13  15  17  19
21   23  25  27
29 31 33 35
i<-0:17 matrix(2*i+1,nrow=3,byrow=TRUE)
and
1  0.5   0.5
0.5     1 0.5
0.5   0.5    1
matrix(rep(c(1,0.5,0.5,0.5),3),nrow=3,ncol=3)

For all the above matrixes I have written a code (as you see below each 
matrix) . If you want to make the above matrixes, will you use my codes 
or will you have other simpler ways for making the above matrixes?


On Sat, May 23, 2020 at 2:39 PM Rui Barradas > wrote:


Hello,

Use diag() and cbind().


special_mat <- function(n){
    if(n %% 2 != 0) {
      msg <- paste(sQuote(n), 'is not a multiple of 2, will use')
      n <- 2*(n%/% 2)
      msg <- paste(msg, sQuote(n))
      warning(msg)
    }
    x <- diag(n/2)
    diag(x) <- seq.int (n/2)
    cbind(x, (n/2 + 1):n)
}

special_mat(6)
special_mat(8)
special_mat(7)


Hope this helps,

Rui Barradas

Às 10:45 de 23/05/20, Vahid Borji escreveu:
 > Hi my friends,
 >
 > I want to make the below matrix in r:
 >
 > 1 0 0 4
 >
 > 0 2 0 5
 >
 > 0 0 3 6
 >
 > I used the below code:
 >
 > matrix(c(1,0,0,0,2,0,0,0,3,4,5,6),nrow=3)
 >
 > My code works. But I do not like my solution way. I am thinking
to find the
 > simplest way for making this matrix. Do you think my code is the
simplest
 > code for making this matrix? If not, could anyone writes a
simpler code
 > than my one?
 >
 >       [[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-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] The best way for making speciall matrix

2020-05-23 Thread Abby Spurdle
This sounds like a homework question...
But... numerical linear algebra rocks...

cbind (diag (1:3), 4:6)


On Sat, May 23, 2020 at 9:46 PM Vahid Borji  wrote:
>
> Hi my friends,
>
> I want to make the below matrix in r:
>
> 1 0 0 4
>
> 0 2 0 5
>
> 0 0 3 6
>
> I used the below code:
>
> matrix(c(1,0,0,0,2,0,0,0,3,4,5,6),nrow=3)
>
> My code works. But I do not like my solution way. I am thinking to find the
> simplest way for making this matrix. Do you think my code is the simplest
> code for making this matrix? If not, could anyone writes a simpler code
> than my one?
>
> [[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-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] The best way for making speciall matrix

2020-05-23 Thread Rui Barradas

Hello,

Use diag() and cbind().


special_mat <- function(n){
  if(n %% 2 != 0) {
msg <- paste(sQuote(n), 'is not a multiple of 2, will use')
n <- 2*(n%/% 2)
msg <- paste(msg, sQuote(n))
warning(msg)
  }
  x <- diag(n/2)
  diag(x) <- seq.int(n/2)
  cbind(x, (n/2 + 1):n)
}

special_mat(6)
special_mat(8)
special_mat(7)


Hope this helps,

Rui Barradas

Às 10:45 de 23/05/20, Vahid Borji escreveu:

Hi my friends,

I want to make the below matrix in r:

1 0 0 4

0 2 0 5

0 0 3 6

I used the below code:

matrix(c(1,0,0,0,2,0,0,0,3,4,5,6),nrow=3)

My code works. But I do not like my solution way. I am thinking to find the
simplest way for making this matrix. Do you think my code is the simplest
code for making this matrix? If not, could anyone writes a simpler code
than my one?

[[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-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] The best way for making speciall matrix

2020-05-23 Thread Ashim Kapoor
Dear Vahid,

Would this help?

> row1<- c(1,0,0,4)
> row2<- c(0,2,0,5)
> row3<- c(0,0,3,6)
> mymatrix <- rbind(row1,row2,row3)
> mymatrix
 [,1] [,2] [,3] [,4]
row11004
row20205
row30036
>

Best Regards,
Ashim

On Sat, May 23, 2020 at 3:16 PM Vahid Borji  wrote:
>
> Hi my friends,
>
> I want to make the below matrix in r:
>
> 1 0 0 4
>
> 0 2 0 5
>
> 0 0 3 6
>
> I used the below code:
>
> matrix(c(1,0,0,0,2,0,0,0,3,4,5,6),nrow=3)
>
> My code works. But I do not like my solution way. I am thinking to find the
> simplest way for making this matrix. Do you think my code is the simplest
> code for making this matrix? If not, could anyone writes a simpler code
> than my one?
>
> [[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-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] The best way for making speciall matrix

2020-05-23 Thread Vahid Borji
Hi my friends,

I want to make the below matrix in r:

1 0 0 4

0 2 0 5

0 0 3 6

I used the below code:

matrix(c(1,0,0,0,2,0,0,0,3,4,5,6),nrow=3)

My code works. But I do not like my solution way. I am thinking to find the
simplest way for making this matrix. Do you think my code is the simplest
code for making this matrix? If not, could anyone writes a simpler code
than my one?

[[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] Bayesian estimation with MCMC

2020-05-23 Thread Christofer Bogaso
Hi,

In python there is a package called pymc3 for Bayesian parameter
estimation with MCMC.

I am curious if there is any equivalent package available for R.

Any pointer will be highly appreciated.

__
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] access for free more than 500 essential Springer Nature textbooks

2020-05-23 Thread Abby Spurdle
> My book is
> Statistical Analysis and Data Display, Richard M. Heiberger, Burt
> Holland, 2nd ed. 2015

In all fairness, I thought should look at your book.

I was quite impressed by the chapter on multiple comparisons.
And may look again, later.

In my personal opinion (diverging slightly), with more and more people
using extensive exploratory-style modelling, I think some of the
methods for multiple comparisons could (and should) be adapted to the
interpretation of exploratory plots.

And returning to your book...
There's relatively comprehensive chapters on multiple regression.
And I'm happy you used the term "explanatory" rather than "independent".
When people use the term "independent variables" (outside a
theoretical context) they usually go my how-did-these people-get-a-job
list.

Some comments:
(1) Expanding on the above point, I couldn't see a section on
interpreting regression coefficients, which is something people often
get wrong.
(2) It had a nice objective/frequentist flavor, but it would have been
nicer to see clearer references to robust, semiparametric and more
general nonparametric methods, even if only brief.

In principle, some of these (but not all) follow the same philosophy
as classical statistics, but allow greater flexibility.

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