Re: [R] quote()/eval() question

2017-09-08 Thread David Winsemius
> On Sep 8, 2017, at 4:55 PM, Axel Urbiz wrote: > > Dear list, > > For a reason it would take me long to explain, I need to do something along > the lines of what's shown below -- i.e., create an object from > dplyr::summarise, and then evaluate it on a data frame. > > I know I could directly

Re: [R] quote()/eval() question

2017-09-08 Thread Duncan Murdoch
On 08/09/2017 7:55 PM, Axel Urbiz wrote: Dear list, For a reason it would take me long to explain, I need to do something along the lines of what's shown below -- i.e., create an object from dplyr::summarise, and then evaluate it on a data frame. I know I could directly do: df %>% dplyr::sum

[R] quote()/eval() question

2017-09-08 Thread Axel Urbiz
Dear list, For a reason it would take me long to explain, I need to do something along the lines of what's shown below -- i.e., create an object from dplyr::summarise, and then evaluate it on a data frame. I know I could directly do: df %>% dplyr::summarise(x1_mean = mean(x1)) but this is not

Re: [R] ISO3 code to 7 continents names

2017-09-08 Thread David Winsemius
> On Sep 7, 2017, at 12:56 PM, David Winsemius wrote: > > >> On Sep 7, 2017, at 12:21 PM, Miluji Sb wrote: >> >> df is a data frame consisting of one variable (iso3 codes) such as >> >> USA >> RUS >> ARG >> BGD >> ITA >> FRA >> >> >> Some of these iso3 codes are repeated and I would like t

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread William Dunlap via R-help
Remove the for loop and all the [i]'s in your code and it will probably go faster. I.e., change f0 <- function (lines) { numbers <- vector("numeric") for (i in 1:length(lines)) { lines[i] <- sub("[^ ]+ +", "", lines[i]) lines[i] <- gsub(" ", "", lines[i]) numbers <

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread Martin Maechler
> peter dalgaard > on Fri, 8 Sep 2017 16:12:21 +0200 writes: >> On 8 Sep 2017, at 15:51 , Martin Møller Skarbiniks >> Pedersen wrote: >> >> On 8 September 2017 at 14:37, peter dalgaard >> wrote: >>> >>> On 8 Sep 2017, at 14:03 , peter dalgaard

[R] one sample permutation test using package 'coin'

2017-09-08 Thread Holger Taschenberger
Using the package ‘exactRankTests’ one can execute a one-sample permutation test for a hypothesized location parameter of 0 like: perm.test(rnorm(30,0)) The package ‘exactRankTests’ seems now to be deprecated in favor of the ‘coin’ package which as I understand is a superset of ‘exactRankTests’

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread peter dalgaard
> On 8 Sep 2017, at 15:51 , Martin Møller Skarbiniks Pedersen > wrote: > > On 8 September 2017 at 14:37, peter dalgaard wrote: >> >> >>> On 8 Sep 2017, at 14:03 , peter dalgaard wrote: >>> >>> x <- scan("~/Downloads/digits.txt") >>> x <- x[-seq(1,22,11)] >> >> ...and, come to think of

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread Martin Møller Skarbiniks Pedersen
On 8 September 2017 at 14:37, peter dalgaard wrote: > > > > On 8 Sep 2017, at 14:03 , peter dalgaard wrote: > > > > x <- scan("~/Downloads/digits.txt") > > x <- x[-seq(1,22,11)] > > ...and, come to think of it, if you really want the 100 random digits: > > xx <- c(outer(x,10^(0:4), "%/%")

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread peter dalgaard
> On 8 Sep 2017, at 14:03 , peter dalgaard wrote: > > x <- scan("~/Downloads/digits.txt") > x <- x[-seq(1,22,11)] ...and, come to think of it, if you really want the 100 random digits: xx <- c(outer(x,10^(0:4), "%/%")) %% 10 -- Peter Dalgaard, Professor, Center for Statistics, Copen

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread PIKAL Petr
Hi see in line > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin > Moller Skarbiniks Pedersen > Sent: Friday, September 8, 2017 11:58 AM > To: r-help@r-project.org > Subject: Re: [R] Optimize code to read text-file with digits > > On 8 Septembe

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread peter dalgaard
Simplest version that I can think of: x <- scan("~/Downloads/digits.txt") x <- x[-seq(1,22,11)] length(x) # 20 hist(x) Now, because it's Friday: How does one work out the theoretical distribution of the following table? > table(table(factor(x,levels=0:9))) 0 1 2 3

Re: [R] post_processor in rmarkdown not working

2017-09-08 Thread Duncan Murdoch
On 08/09/2017 3:56 AM, Thierry Onkelinx wrote: That is strange. Another function in the same package (INBOmd::inbo_rapport) uses the same trick. I think the issue there is that the LaTeX code is valid before the post-processor is run, it just re-orders things. So rmarkdown::render runs Pand

[R] nested loop

2017-09-08 Thread Hemant Sain
i have a vector containing values ranging from 0 to 24 i want to create another variable which can categorize those values like this please help me with an R code Thanks *Value New_Var*10 -5 30 -5 50 -5 96-10 76-10 56-

Re: [R] Nested loop R code

2017-09-08 Thread Ulrik Stervbo
Hi Hemant, please write to the r-help list in the future. Look at the cut () function to solve your problem. Also, you have a problem in your example - 5 is placed in two different categories. HTH Ulrik On Fri, 8 Sep 2017 at 12:16 Hemant Sain wrote: > i have a vector containing values rangin

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread Martin Møller Skarbiniks Pedersen
On 8 September 2017 at 11:25, PIKAL Petr wrote: > > Moller Skarbiniks Pedersen > My program which is slow looks like this: > > > > filename <- "digits.txt" > > lines <- readLines(filename) > > why you do not read a file as a whole e.g. by > > lines<-read.table("digits.txt") > Good idea. > > An

Re: [R] Optimize code to read text-file with digits

2017-09-08 Thread PIKAL Petr
Hi see in line > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin > Moller Skarbiniks Pedersen > Sent: Friday, September 8, 2017 10:49 AM > To: r-help@r-project.org > Subject: [R] Optimize code to read text-file with digits > > Hi, > > Every da

[R] Optimize code to read text-file with digits

2017-09-08 Thread Martin Møller Skarbiniks Pedersen
Hi, Every day I try to write some small R programs to improve my R-skills. Yesterday I wrote a small program to read the digits from "A Million Random Digits" from RAND. My code works but it is very slow and I guess the code is not optimal. The digits.txt file downloaded from https://www.ra

Re: [R] post_processor in rmarkdown not working

2017-09-08 Thread Thierry Onkelinx
That is strange. Another function in the same package (INBOmd::inbo_rapport) uses the same trick. I actually started by copying the post_processor() from that function. INBOmd::inbo_rapport() works both with and without BibTex. Working examples are source/inbo_rapport and source/inbo_rapport_basic