similar to: Competing with SPSS and SAS: improving code that loops through rows (data manipulation)

Displaying 20 results from an estimated 9000 matches similar to: "Competing with SPSS and SAS: improving code that loops through rows (data manipulation)"

2010 Mar 30
4
Code is too slow: mean-centering variables in a data frame by subgroup
Dear R-ers, I have a large data frame (several thousands of rows and about 2.5 thousand columns). One variable ("group") is a grouping variable with over 30 levels. And I have a lot of NAs. For each variable, I need to divide each value by variable mean - by subgroup. I have the code but it's way too slow - takes me about 1.5 hours. Below is a data example and my code that is too
2011 Mar 30
2
summing values by week - based on daily dates - but with some dates missing
Dear everybody, I have the following challenge. I have a data set with 2 subgroups, dates (days), and corresponding values (see example code below). Within each subgroup: I need to aggregate (sum) the values by week - for weeks that start on a Monday (for example, 2008-12-29 was a Monday). I find it difficult because I have missing dates in my data - so that sometimes I don't even have the
2010 Oct 18
1
Question about lme (mixed effects regression)
Hello! If I run this example: library(nlme) fm1 <- lme(distance ~ age+Sex, Orthodont, random = ~ age + Sex| Subject) If I run: summary(fm1) then I can see the fixed effects for age and sex (17.7 for intercept, 0.66 for age, and -1.66 for SexFemale) If I run: ranef(fm1) Then it looks like it's producing the random effects for each subgroup (in this example - each subject). For example,
2016 Dec 31
2
SCCP is not always correct in presence of undef (+ proposed fix)
Hi Daniel, On Fri, Dec 30, 2016 at 10:55 PM, Daniel Berlin <dberlin at dberlin.org> wrote: >> Right, but we are talking about "when, in the intermediate state, can i >> transform an undef to a different value". >> >> Remember you can only go down the lattice. So you can't make undef >> constant, and then discover it's wrong, and go back up :)
2011 Apr 04
2
merging 2 frames while keeping all the entries from the "reference" frame
Hello! I have my data frame "mydata" (below) and data frame "reference" - that contains all the dates I would like to be present in the final data frame. I am trying to merge them so that the the result data frame contains all 8 dates in both subgroups (i.e., Group1 should have 8 rows and Group2 too). But when I merge it it's not coming out this way. Any hint would be
2016 Dec 31
0
SCCP is not always correct in presence of undef (+ proposed fix)
Hi David, Looking at the original bug, it seems like a straightforward undef-propagation bug to me -- SCCP was folding "or undef, constant" to "undef", which is wrong. Why is changing that not the fix? That is, some variant of diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 8a6be97..45f1241 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++
2016 Dec 31
0
SCCP is not always correct in presence of undef (+ proposed fix)
On Fri, Dec 30, 2016 at 11:55 PM, Sanjoy Das <sanjoy at playingwithpointers.com > wrote: > Hi Daniel, > > On Fri, Dec 30, 2016 at 10:55 PM, Daniel Berlin <dberlin at dberlin.org> > wrote: > >> Right, but we are talking about "when, in the intermediate state, can i > >> transform an undef to a different value". > >> > >>
2016 Dec 31
4
SCCP is not always correct in presence of undef (+ proposed fix)
On Fri, Dec 30, 2016, 9:04 PM Sanjoy Das via llvm-dev < llvm-dev at lists.llvm.org> wrote: > Hi David, > > Looking at the original bug, it seems like a straightforward > undef-propagation bug to me -- SCCP was folding "or undef, constant" > to "undef", which is wrong. Why is changing that not the fix? That > is, some variant of > You would still
2010 Sep 27
1
stacked area chart
Dear R-ers! Asking for your help with building the stacked area chart for the following simple data (several variables - with date on the X axis): ### Creating a data set my.data<-data.frame(date=c(20080301,20080402,20080503,20090301,20090402,20090503,20100301,20100402,20100503), x=c(1.1,1.0,1.6,1,2,1.5,2.1,1.3,1.9),y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9),
2009 Sep 22
1
any way to make it work faster (deleting rows that contain certain values)
Hello, dear R'ers, index<-expand.grid(1:7,1:4,1:4,1:4,1:4,1:4,1:4,1:4,1:4,1:4,1:4) In this case, dim(index) is 7,340,032 (!) and 11. I realize it's huge. Then, I am trying to get rid of the undesired combinations of columns. They should not contain identical values in any 2 columns. Also if column 1 has a value of 5, there should be no 2 in any other column, if column 1 has a value
2010 Mar 09
2
looping through predictors
Dear R-ers, I have a data frame data with predictors x1 through x5 and the response variable y. I am running a simple regression: reg<-lm(y~x1, data=data) I would like to loop through all predictors. Something like: predictors<-c("x1","x2",... "x10) for(i in predictors){ reg<-lm(y~i) etc. } But it's not working. I am getting an error: Error in
2010 Nov 03
2
avoiding too many loops - reshaping data
Hello! I have a data frame like this one: mydf<-data.frame(city=c("a","a","a","a","a","a","a","a","b","b","b","b","b","b","b","b"),
2010 Oct 04
1
adding a legend to the plot (but outside of it)
Hello! My code below creates a data frame and a plot for it. However, I can't figure out how to add a legend that is not ON the plot itself, but outside of it (e.g., to the right of my graph or below it). I tried something: I put a line par(xpd=T, mar=par()$mar+c(0,0,0,4)) right before my plot command), but that screwed up all my gridlines - they covered all graph and do not coincide with
2009 Nov 29
3
How to z-standardize for subgroups?
Hi folks, I have a dataframe df.vars with the follwing structure: var1 var2 var3 group Group is a factor. Now I want to standardize the vars 1-3 (actually - there are many more) by class, so I define z.mean.sd <- function(data){ return.values <- (data - mean(data)) / (sd(data)) return(return.values) } now I can call for each var z.var1 <- by(df.vars$var1, group,
2011 May 19
1
Creating a "shifted" month (one that starts not on the first of each month but on another date)
Hello! I have a data frame with dates. I need to create a new "month" that starts on the 20th of each month - because I'll need to aggregate my data later by that "shifted" month. I wrote the code below and it works. However, I was wondering if there is some ready-made function in some package - that makes it easier/more elegant? Thanks a lot! # Example data:
2016 Dec 31
0
SCCP is not always correct in presence of undef (+ proposed fix)
On Fri, Dec 30, 2016 at 10:54 PM, Daniel Berlin <dberlin at dberlin.org> wrote: > > > On Fri, Dec 30, 2016 at 10:01 PM, Sanjoy Das <sanjoy at playingwithpointers. > com> wrote: > >> Hi Daniel, >> >> On Fri, Dec 30, 2016 at 9:47 PM, Daniel Berlin <dberlin at dberlin.org> >> wrote: >> >> >> >>> Is there a case in
2011 Feb 25
6
preventing repeat in "paste"
Hello! s<-"start"; e<-"end" middle<-as.character(c(1,2,3)) I would like to get the following result: "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" How can I avoide this (undesired) result: paste(s,middle,e,sep=" ") Thank you! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com
2011 May 21
4
Looping through values in a data frame that are >zero
Hello! I've tried for a while - but can't figure it out. I have data frame x: y=c("a","b","c","d","e") z=c("m","n","o","p","r") a=c(0,0,1,0,0) b=c(2,0,0,0,0) c=c(0,0,0,4,0) x<-data.frame(y,z,a,b,c,stringsAsFactors=F) str(x) Some of the values in columns a,b, and c are >0: I need to
2010 Oct 01
3
Suppressing printing in the function
Hello! I wrote a function that returns a data frame. Nowhere in the function do I say print(my.data.frame), but when I run the function - the data frame is printed on the console. Is there any way to suppress it? Thank you! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com
2009 Oct 13
4
replacing period with a space
Dear R-ers! I have x as a variable in a data frame x. x<-data.frame(x=c("aa.bb","cc.dd.ee")) x$x<-as.character(x$x) x I am sorry for such a simple question - but how can I replace all periods in x$x with spaces? sub('.', ' ', x$x) - removes all letters to the left of each period... Thanks a lot for your advice! -- Dimitri Liakhovitski Ninah.com