Re: [R] Problems with closing R

2019-07-08 Thread jeremiah rounds
It can seem like it is hung when you default to saving your workspace on close and you have a very large workspace in memory relative to your hard drive write speed. Are you sure it isn't that? On Sun, Jul 7, 2019 at 1:18 PM Spencer Brackett < spbracket...@saintjosephhs.com> wrote: > Thank you.

Re: [R] difference between ifelse and if...else?

2017-12-13 Thread jeremiah rounds
ifelse is vectorized. On Wed, Dec 13, 2017 at 7:31 AM, Jinsong Zhao wrote: > Hi there, > > I don't know why the following codes are return different results. > > > ifelse(3 > 2, 1:3, length(1:3)) > [1] 1 > > if (3 > 2) 1:3 else length(1:3) > [1] 1 2 3 > > Any hints? > > Best, > Jinsong > > _

Re: [R] JSON data in data frame

2017-01-13 Thread jeremiah rounds
I TAd a course in R computing and the first thing I told students was "inspect. inspect. inspect." d1 <- fromJSON(' http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric&appid=ec0313a918fa729d4372555ada5fb1f8 ') names(d1) str(d1) d1 d1$list your_data = d1$list On Fri,

Re: [R] About populating a dataframe in a loop

2017-01-06 Thread jeremiah rounds
As a rule never rbind in a loop. It has O(n^2) run time because the rbind itself can be O(n) (where n is the number of data.frames). Instead either put them all into a list with lapply or vector("list", length=) and then datatable::rbindlist, do.call(rbind, thelist) or use the equivalent from dply

Re: [R] unique dates per ID

2016-11-15 Thread jeremiah rounds
library(data.table) setDT(df) setkeyv(df, c("Subject", "dates")) unique(df) #gets what you want. On Mon, Nov 14, 2016 at 11:38 PM, Jim Lemon wrote: > Hi Farnoosh, > Try this: > > for(id in unique(df$Subject)) { > whichsub<-df$Subject==id > if(exists("newdf")) > newdf<-rbind(newdf,df[whichsu

Re: [R] Function argument and scope

2016-11-14 Thread jeremiah rounds
Hi, Didn't bother to run the code because someone else said it might do what you intended, and also your problem description was complete unto itself. The issue is that R copies on change. You are thinking like you have a reference, which you do not. That is not very R like in style, but it cer

Re: [R] Putting a bunch of Excel files as data.frames into a list fails

2016-09-28 Thread jeremiah rounds
Try changing: v_list_of_files[v_file] to: v_list_of_files[[v_file]] Also are you sure you are not generating warnings? For example, l = list() l["iris"] = iris; Also, you can change it to lapply(v_files, function(v_file){...}) Have a good one, Jeremiah On Wed, Sep 28, 2016 at 8:02 AM, wrote:

Re: [R] why data.frame, mutate package and not lists

2016-09-14 Thread jeremiah rounds
There is also this syntax for adding variables df[, "var5"] = 1:10 and the syntax sugar for row-oriented storage: df[1:5,] On Wed, Sep 14, 2016 at 11:40 AM, jeremiah rounds wrote: > "If you want to add variable to data.frame you have to use attach, detach. > Right?" &

Re: [R] why data.frame, mutate package and not lists

2016-09-14 Thread jeremiah rounds
"If you want to add variable to data.frame you have to use attach, detach. Right?" Not quite. Use it like a list to add a variable to a data.frame e.g. df = list() df$var1 = 1:10 df = as.data.frame(df) df$var2 = 1:10 df[["var3"]] = 1:10 df df = as.list(df) df$var4 = 1:10 as.data.frame(df) Ironi

Re: [R] Help with strftime error "character string is not in a standard unambiguous format"

2016-09-12 Thread jeremiah rounds
Not sure what the issue is with the provided code but note: library(lubridate) lubridate::dmy_hm("Thu, 25 Aug 2016 6:34 PM") [1] "2016-08-25 18:34:00 UTC" Though if you go that route: set the TZ because on the timestamp it is ambiguous. On Sun, Sep 11, 2016 at 10:57 PM, Chris Evans wrote: >

Re: [R] Time format lagging issue

2016-08-31 Thread jeremiah rounds
Building on Don's example here is something that looks a lot like what I do every day: Sys.setenv(TZ="UTC") mydf <- data.frame(t1=c('2011-12-31-22-30', '2011-12-31-23-30')) library(lubridate) mydf$timestamp = lubridate::ymd_hm(mydf$t1) mydf$t2 = mydf$timestamp - period(minute=30) On Wed, Aug 31,

Re: [R] remove rows based on row mean

2016-08-18 Thread jeremiah rounds
oh I forgot I renamed sm. dt = sm library(data.table) setDT(dt) op = function(s){ mean0 = apply(s, 1, mean) ret = s[which.max(mean0)] ret$mean = mean0 ret } max_row = dt[, op(.SD), by = "Gene"] Thanks, Jeremiah On Thu, Aug 18, 2016 at 3:21 PM, jeremiah rounds wrote: > libra

Re: [R] remove rows based on row mean

2016-08-18 Thread jeremiah rounds
library(data.table) setDT(dt) op = function(s){ mean0 = apply(s, 1, mean) ret = s[which.max(mean0)] ret$mean = mean0 ret } max_row = dt[, op(.SD), by = "Gene"] Thanks, Jeremiah On Thu, Aug 18, 2016 at 2:33 PM, Adrian Johnson wrote: > Hi Group, > I have a data matrix sm (dput code given below).

Re: [R] Creating Dummy Var in R for regression?

2016-08-05 Thread jeremiah rounds
Something like: d = data.frame(score = sample(1:10, 100, replace=TRUE)) d$score_t = "low" d$score_t[d$score > 3] = "medium" d$score_t[d$score >7 ] = "high" d$score_t = factor(d$score_t, levels = c("low", "medium", "high"), ordered=TRUE) #set ordered = FALSE for dummy variables X = model.matrix(

Re: [R] Reduce woes

2016-07-28 Thread jeremiah rounds
Basically using Reduce as an lapply in that example, but I think that was caused by how people started talking about things in the first place =) But the point is the accumulator can be anything as far as I can tell. On Thu, Jul 28, 2016 at 12:14 PM, jeremiah rounds wrote: > Re: > &qu

Re: [R] Reduce woes

2016-07-28 Thread jeremiah rounds
Re: "What I'm trying to work out is how to have the accumulator in Reduce not be the same type as the elements of the vector/list being reduced - ideally it could be an S3 instance, list, vector, or data frame." Pretty sure that is not true. See code that follows. I would never solve this task i

Re: [R] Reducing execution time

2016-07-27 Thread jeremiah rounds
Correction to my code. I created a "doc" variable because I was thinking of doing something faster, but I never did the change. grep needed to work on the original source "dat" to be used for counting. Fixed: combs = structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L, 34L, 34L, 77L, 65L

Re: [R] Reducing execution time

2016-07-27 Thread jeremiah rounds
If I understood the request this is the same programming task as counting words in a document and counting character sequences in a string or matching bytes in byte arrays (though you don't want to go down that far) You can do something like what follows. There are also vectorized greps in strin

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
by.column = FALSE), >> roll_lm = roll_lm(coredata(z[, 1, drop = F]), coredata(z[, 2, drop = >> F]), 4, >> center = FALSE))[1:4] >> >> >> test replications elapsed relative >> 1 fastLm 1000.221.000 >> 2 lm

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
, 2, drop = > F]), 4, > center = FALSE))[1:4] > > > test replications elapsed relative > 1 fastLm 1000.221.000 > 2 lm 1000.723.273 > 3 roll_lm 1000.642.909 > > On Thu, Jul 21, 2016 at 3:45 PM, jeremiah

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
ix multiplications may not be. This should be kept in mind when writing > your own Rcpp code for plugging it into RcppRoll. > > But I haven't check what the roll package does and how reliable that is... > > hth, > Z > > > On Thu, 21 Jul 2016, jeremiah rounds wrote: > &

[R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread jeremiah rounds
Hi, A not unusual task is performing a multiple regression in a rolling window on a time-series.A standard piece of advice for doing in R is something like the code that follows at the end of the email. I am currently using an "embed" variant of that code and that piece of advice is out there

Re: [R] if + is.na

2009-06-14 Thread Jeremiah Rounds
Your error message is because "if" wants a single value and you are giving it a vector. Typically you want to use functions "all" or any" to correct this error message (look them up ?all ?any) and eg if(any(is.na(...))) But in this case to accomplish the task you're after I don't even t

Re: [R] help to speed up loops in r

2009-06-09 Thread Jeremiah Rounds
time it is absolute essential to use the right data structure for the job. Hope this is of assistance, Jeremiah Rounds > Date: Mon, 8 Jun 2009 15:45:40 + > From: amitrh...@yahoo.co.uk > To: r-help@r-project.org > Subject: [R] help to speed up loops in r > > >

Re: [R] how to randomly eliminate half the entries in a vector?

2009-02-17 Thread Jeremiah Rounds
Here is what I got for script through your third question: set.seed(1) x1 = rbinom(200,1,.5) x2 = rbinom(200,1,.5) differ = x1 != x2 differ.indexes = (1:length(x1))[differ == TRUE] #you were unclear if you want to round up or round down on odd index of differ.indexes n = floor( length(d

Re: [R] How to paste graph from R in Latex?

2008-05-17 Thread Jeremiah Rounds
For school work I use png. Png files are more efficient size/quality wise than png, and also lend themselves to more generic application/viewing than ps. In R this typically takes the form of: setwd(...) #set working directory before starting any work typically at the top of scripts

Re: [R] heatmap on pre-established hclust output?

2008-05-16 Thread Jeremiah Rounds
at just returning the results of your more complicated clustering in that call without actually doing the calculations. Jeremiah Rounds Graduate Student Utah State University > > __> R-help@r-project.org > > mailing list> https://stat.et

Re: [R] Newbie question about vector matrix multiplication

2008-05-14 Thread Jeremiah Rounds
> Date: Wed, 14 May 2008 15:18:32 -0400 > From: [EMAIL PROTECTED] > To: r-help@r-project.org > Subject: [R] Newbie question about vector matrix multiplication > > Hello All, > > I have a covariance matrix, generated by read.table, and cov: > > co<-cov(read.table("c:/r.x")) > > X Y Z > > X 0.001

Re: [R] strip white in character strings

2008-05-14 Thread Jeremiah Rounds
> Date: Wed, 14 May 2008 12:06:39 -0400 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: [R] strip white in character strings > > Dear all, > > I have several datasets and I want to generate pdf plots from them. > I also want to generate automatically the names of the files. They ar

Re: [R] array dimension changes with assignment

2008-05-13 Thread Jeremiah Rounds
what you wanted to happen happened just fine. So the question you might ask yourself is: what is different? And that leads to asking what class is the SNP1 object? If you can coerce into an array you probably can avoid the issue. Jeremiah Rounds Graduate Student