Re: [R] a fast way to do my job

2024-08-09 Thread Bert Gunter
Better idea, Ben! It would work as you might expect it to to produce the same results as the above: ##first make sure your regressor is a matrix: pur2 <- matrix(purity2, ncol =1) ## convert the data frame variables into a matrix dat <- as.matrix(gem751be.rpkm[ , 74:35164]) ##then result <- residu

Re: [R] a fast way to do my job

2024-08-09 Thread Ben Bolker
You can also fit a linear model with a matrix-valued response variable, which should be even faster (not sure off the top of my head how to get the residuals and reshape them to the dimensions you want) On Fri, Aug 9, 2024 at 9:31 PM Bert Gunter wrote: > > See ?lm.fit. > I must be missing somethi

Re: [R] a fast way to do my job

2024-08-09 Thread Bert Gunter
See ?lm.fit. I must be missing something, because: results <- sapply(74:35164, \(i) residuals(lm.fit(purity2, gem751be.rpkm[, i] ))) would give you a 751 x 35091 matrix of the residuals from each of the regressions. I assume it will be considerably faster than all the overhead you are carrying in

Re: [R] a fast way to do my job

2024-08-09 Thread Yuan Chun Ding via R-help
Dear R users, I am running the following code below, the gem751be.rpkm is a dataframe with dim of 751 samples by 35164 variables, 73 phenotypic variables in the furst to 73rd column and 35091 genomic variables or genes in the 74th to 35164th columns. What I need to do is to calculate the res

Re: [R] WDI package commands timing out and not working

2024-08-09 Thread Ivan Krylov via R-help
В Fri, 9 Aug 2024 20:25:51 +0530 Anupam Tyagi пишет: > I am trying this in Bengaluru, India, using R-studio. I tried > downloading a single variable. It happened fast, in less than 5 > seconds. I tried downloading six variables, it took much longer, but > less than a minute. Tried eight variables

Re: [R] WDI package commands timing out and not working

2024-08-09 Thread Anupam Tyagi
Thanks, Martin. I am trying this in Bengaluru, India, using R-studio. I tried downloading a single variable. It happened fast, in less than 5 seconds. I tried downloading six variables, it took much longer, but less than a minute. Tried eight variables and it did not download even in five minutes.

Re: [R] WDI package commands timing out and not working

2024-08-09 Thread Martin Maechler
> Ivan Krylov via R-help > on Fri, 9 Aug 2024 15:23:58 +0300 writes: > В Thu, 8 Aug 2024 12:43:23 +0530 > Anupam Tyagi пишет: >> In open.connection(con, "rb") : >> URL >> 'https://api.worldbank.org/v2/en/country/OED/indicator/NY.ADJ.NNAT.GN.ZS?format=json&date=1

Re: [R] WDI package commands timing out and not working

2024-08-09 Thread Anupam Tyagi
I tried running the same command on my home computer, and it downloaded in less than 30 seconds. So, it seems the problem is with internet connection at work. Thanks, Ivan. On Fri, 9 Aug 2024 at 18:30, Anupam Tyagi wrote: > In the browser the link downloads immediately, in less than a second. I

Re: [R] WDI package commands timing out and not working

2024-08-09 Thread Anupam Tyagi
In the browser the link downloads immediately, in less than a second. I let the command run in R for five minutes, using R Studio. Nothing happened. On Fri, 9 Aug 2024 at 17:54, Ivan Krylov wrote: > В Thu, 8 Aug 2024 12:43:23 +0530 > Anupam Tyagi пишет: > > > In open.connection(con, "rb") : > >

Re: [R] WDI package commands timing out and not working

2024-08-09 Thread Ivan Krylov via R-help
В Thu, 8 Aug 2024 12:43:23 +0530 Anupam Tyagi пишет: > In open.connection(con, "rb") : > URL > 'https://api.worldbank.org/v2/en/country/OED/indicator/NY.ADJ.NNAT.GN.ZS?format=json&date=1977:2020&per_page=32500&page=1': > Timeout of 60 seconds was reached If you try to open the link in the brow

Re: [R] If loop

2024-08-09 Thread CALUM POLWART
Oh I thought that was just my experience of it !! So didn't want to slate it too much!! Yes, I nearly said "without making it an object of objects". I guess it depends what they want to do with those objects in the end. Usually if I want a function to manipulate two things I create two functions.

Re: [R] If loop

2024-08-09 Thread Duncan Murdoch
On 2024-08-09 6:21 a.m., Bert Gunter wrote: "Or use <<- assignment I think. (I usually return, but return can only return one object and I think you want two or more" You can return any number of objects by putting them in a list and returning the list. Use of "<<-" is rarely a good idea in R.

Re: [R] If loop

2024-08-09 Thread Steven Yen
Thanks. Hmm, I like the idea of returning a list. I occasionally use “invisible” and am still trying to figure out its difference with return. Where do I read about <<- assignment? On 8/9/2024 6:21 PM, Bert Gunter wrote: > "Or use <<- assignment I think. (I usually return, but return can only >

Re: [R] If loop

2024-08-09 Thread Bert Gunter
"Or use <<- assignment I think. (I usually return, but return can only return one object and I think you want two or more" You can return any number of objects by putting them in a list and returning the list. Use of "<<-" is rarely a good idea in R. -- Bert On Fri, Aug 9, 2024 at 1:53 AM CALUM

Re: [R] If loop

2024-08-09 Thread CALUM POLWART
OK. The fact it's in a function is making things clearer. Are you trying to update the values of an object from within the function, and have them available outside the function. I don't speak functional programming articulately enough but basically v <- 1 funA <- function() { v <- v+1 } funA()

Re: [R] If loop

2024-08-09 Thread Steven Yen
Thanks. Hmm. The loop is doing what it is supposed to do. > try1<-function(joint12=FALSE,marg1=FALSE,marg2=FALSE, +    cond12=FALSE,cond21=FALSE){ + # *** + # Testing if loop + # *** + if(j