similar to: aggregate(as.formula("some formula"), data, function) error when called from in a function

Displaying 20 results from an estimated 1000 matches similar to: "aggregate(as.formula("some formula"), data, function) error when called from in a function"

2012 Jun 05
4
need descriptive help
Hi all, I'm new to using R, and apologize for simplicity of this question. I'm using a data set with over 60,000 observations, Two variables are patient ID, and cost incurred by the patient. I'd like to generate frequency/table by patient and cost IF the total cost is over 2000. Right now I'm using: by(x$cost, x$patient, sum) but this generates a huge list for each patient.
2008 Mar 29
3
Generating maps in R
Greetings! I am trying plot some data on a map in R. Here's the scenario. I have a variable called probworkinghealthy which contains a predicted probability of employment for every individual in my sample (about 100,000 observations). I have another variable, called a001ter, which contains the subject of residency in the Russian Federation (akin to a US state) for every individual in the
2007 Dec 16
2
question about the aggregate function with respect to order of levels of grouping elements
Hi, I am using aggregate() to add up groups of data according to year and month. It seems that the function aggregate() automatically sorts the levels of factors of the grouping elements, even if the order of the levels of factors is supplied. I am wondering if this is a bug, or if I missed something important. Below is an example that shows what I mean. Does anyone know if this is just the way
2011 Jul 14
2
cbind in aggregate formula - based on an existing object (vector)
Hello! I am aggregating using a formula in aggregate - of the type: aggregate(cbind(var1,var2,var3)~factor1+factor2,sum,data=mydata) However, I actually have an object (vector of my variables to be aggregated): myvars<-c("var1","var2","var3") I'd like my aggregate formula (its "cbind" part) to be able to use my "myvars" object. Is it
2012 Sep 07
7
Producing a table with mean values
Hi All, I have a data set wit three size classes (pico, nano and micro) and 12 different sites (Seamounts). I want to produce a table with the mean and standard deviation values for each site. Seamount Pico Nano Micro Total_Ch 1 Off_Mount 1 0.0691 0.24200 0.00100 0.31210 2 Off_Mount 1 0.0938 0.00521 0.02060 0.11961 3 Off_Mount 1 0.1130 0.20000 0.06620 0.37920 4 Off_Mount 1
2011 Apr 07
0
classification
Dear all, this is not a pure R question, but really about how to set up a multinomial logistic regression model to do a multi-class classification. I would really appreciate if any of you would give me some of your thoughts and recommendation. Let's say we have 3-class classification problem: A, B and C. I have certain number of samples, with each sample, I have 3 variables (Xa, Xb and
2012 Feb 28
1
group calculations with other columns for the ride
Hello, I can get the median for each factor, but I'd like another column to go with each factor. The nm column is a long name for the lvls column. So unique work except for the order can get messed up. Example: x =
2012 May 08
2
How to deal with a dataframe within a dataframe?
Hello all, I am doing an aggregation where the aggregating function returns not a single numeric value but a vector of two elements using return(c(val1, val2)). I don't know how to access the individual columns of that vector in the resulting dataframe though. How is this done correctly? Thanks, robert > agg <- aggregate(formula=df$value ~ df$quarter + df$tool, + FUN=cp.cpk,
2012 Oct 24
1
Getting ordered factor levels from C
I'm working on an R package in C and can't seem to get the same level information about a factor that the R console displays. If I define a factor as: lvls <- factor(c('red','blue','blue','green','red'), c('blue','green','red'), ordered=TRUE) When I get the "levels" attribute in C, I get back the the first
2008 Jul 03
1
lm() question
I have data that looks like YC Age Num 82 11 2 83 10 0 84 9 8 85 8 21 86 7 49 87 6 18 88 5 79 89 4 28 90 3 273 91 2 175 with a program mod1=lm(log(Num+1)~YC, data=box44) plot(log(Num+1)~YC, data=box44, pch=19, xlab="Year Class", ylab="Loge Number at age", ylim=c(0,6), xlim=c(91,82)) abline(lm(log(Num+1)~YC), col="blue", lwd=2) summary(mod1) I need to
2007 May 07
0
Analyzing "Stacked" Time Series
I have a question about pooling or "stacking" several time series ?samples? (sorry in advance for the long, possibly confusing, message). I'm sure I'm revealing far more ignorance than I'm aware of, but that's why I'm sending this... [Example at bottom] I have regional migration flows (?samples?) from, say, regions A to B, A to C, B to A, ?., C to B (Noted as
2010 Jul 29
1
[PATCH] Reflow logic to make it easier to follow
The control flow was: if (!y) { ppix = ... } if (y) { ... } else if (x) { use ppix for something } else { use ppix for something } Merge the if(!y) block with the two else branches. This avoids a false-positive in the clang static analyzer, it can't know that !y and x are mutually exclusive. The result looks something like this: if (y) { ... } else { ppix = ... if (x) {
2002 Oct 29
1
samba compiling error
Hello, I have error on compiling time I tried on HP-UX 11.00 system with gcc version 3.1 to compile samba source Samba latest version source was dowloaded from www.us1.samba.org/samba/ftp I attached log file with this error thank you. begin 600 samba_make.log.doc M(R!M86ME#0HO=7-R+VQO8V%L+W-A;6)A+V)I;B(@+410241$25(](B]U<W(O M;&]C86PO<V%M8F$O=F%R+VQO8VMS(B
2006 Aug 04
1
Integration and Loop in R
Dear All, I have seldom needed to use loops in R, but now I need to code a loop with a stride different from one. In the R manual I downloaded I have the example: > xc <- split(x, ind) > yc <- split(y, ind) > for (i in 1:length(yc)) { plot(xc[[i]], yc[[i]]); abline(lsfit(xc[[i]], yc[[i]])) } but in my case I'd like to add a condition so that i varies by 4 from one go
2005 Jun 26
4
Mixed model
Hi All, I am currently conducting a mixed model. I have 7 repeated measures on a simulated clinical trial. If I understand the model correctly, the outcome is the measure (as a factor) the predictors are clinical group and trial (1-7). The fixed factors are the measure and group. The random factors are the intercept and id and group. I tried using 2 functions to calculate mixed effects.
2018 May 16
2
Bilateral matrix
xtabs does this automatically if your cross classifying variables are factors with levels all the cities (sorted, if you like): > x <- sample(letters[1:5],8, rep=TRUE) > y <- sample(letters[1:5],8,rep=TRUE) > xtabs(~ x + y) y x c d e a 1 0 0 b 0 0 1 c 1 0 0 d 1 1 1 e 1 1 0 > lvls <- sort(union(x,y)) > x <- factor(x, levels = lvls) > y <-
2011 Nov 22
5
x, y for point of intersection
Hi everyone, ? I am trying to get a point of intersection between a polyline and a straight line ?.. and get the x and y coordinates of this point. For exemplification consider this: ? ? set.seed(123) ? k1 <-rnorm(100, mean=1.77, sd=3.33) ?k1 <- sort(k1) q1 <- rnorm(100, mean=2.37, sd=0.74) q1 <- sort(q1, decreasing = TRUE) plot(k1, q1, xlim <- c((min(k1)-5),
2011 May 19
3
problem with optim()
Dear R-users, I would like to maximize the function g above which depends on 4 parameters (2 vectors, 1 real number, and 1 matrix) using optim() and BFGS method. Here is my code: # fonction to maximize g=function(x) { x1 = x[1:ncol(X)] x2 = x[(ncol(X)+1)] x3 = matrix(x[(ncol(X)+2):(ncol(X)+1+ncol(X)*ncol(Y))],nrow=ncol(X),ncol=ncol(Y)) x4 = x[(ncol(X)+1+ncol(X)*ncol(Y)+1):length(x)]
2018 May 17
0
Bilateral matrix
Dear William and Ben, Thank you for your replies and elegant solutions. I am having trouble with the fact that two of the previous locations do not appear in current locations (that is no one moved to OKC and Dallas from other cities), so these two cities are not being included in the output. I have provided a better sample of the data and the ideal output (wide form - a 10x10 bilateral matrix)
2009 Mar 12
8
help with loop
Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this:   c <- list()   for(i in 1:ncol(mydata)) {   for(j in 2:nrow(mydata)) {   c[[i]] <- sum(yc[j,i] - yc[(j-1),i])   }}} As for the columns it works pretty fine, but it only