similar to: how to calculate "conditional" mean?

Displaying 20 results from an estimated 30000 matches similar to: "how to calculate "conditional" mean?"

2007 Feb 01
2
How can I calculate conditional mean in a large dataset including date data
Dear R users, I have a dataframe with two columns: first column is date data (e.g. 1/1/2000 with character format: daily data from 1/1/1970 till 31/12/2003) and second column is temperature value. Now I'd like to calculate mean for each month in a year (i.e. May 2001, June 1997) and mean for each month in all of years. As the number of days in some months is different from others I could
2008 Dec 28
2
Conditional operation on multiple columns from two data frames
Hi- I have two data frames for which I wish to conditionally subtract the values of one dataframe from the other. I want to subtract df1$x from df2$x when their id is equal and the absolute value of difference between the dates is 12 hours or less. If there is no match of equal id's and dates less than 12 hours apart I want it to return "NA". Note that df1 has missing values in x
2009 Jun 03
2
Create a time interval from a single time variable
I am trying to set up a data set for a survival analysis with time-varying covariates. The data is already in a long format, but does not have a variable to signify the stopping point for the interval. The variable DaysEnrolled is the variable I would like to use to form this interval. This is what I have now: ID Age DaysEnrolled HAZ WAZ WHZ Food onARV
2011 May 07
4
how to calculate the mean of a group in a table
Hi its me again I don't mean to get on your nerves, but the use of R proofs to be a bit more complicated than envisaged. I would like to calculate the mean of a group of values, here "wage_accepted". The group is determined by the stage and period, so in the end there should be a column with the values of the wages in period 1 stage1, period 1 stage 2, period 2 stage1...
2011 May 16
2
conditional rowsums in sapply
Hi all I have a data frame with duplicate columns and i want to remove duplicates by adding rows in each group of duplicates, but have lots of NA's. Data: dfrm <- data.frame(a = 1:4, b= 1:4, cc= 1:4, dd=1:10, ee=1:4) names(dfrm) <- c("a", "a", "b", "b", "b") dfrm[3,2:3]<-NA dfrm a a b b b 1 1 1 1 1 1 2 2 2 2 2 2 3
2007 Nov 17
2
Getting Annual (Conditional) Averages
Hello, I'm very new to R, and so my question is simple. I have data record with 80 years of daily temperatures in one long string. The dates are also recorded, in YYMMDD format. I'd like to learn an elegant simple way to pull out the annual averages. (Obviously, every 4th year has 366 days.) I know I can set up a formal loop to create annual records and then average. But R
2010 Jun 15
6
working with zoo time index ??
Hello Where could I find examples on how to work with the time index in a timeseries or zoo series? Let say I've got this series DATA 1990-01-01 10:00:00 0.900 1990-01-01 10:01:00 0.910 1990-01-01 10:03:00 0.905 1990-01-01 10:04:00 0.905 1990-01-01 10:05:00 0.890 ....................... 2000-12-31 20:00:00 0.992 How do I make simple calculations such as ... ? Calculate the
2005 Jan 11
1
Nested ifelse - is there a better way?
Dear r-help, I'm interested in finding a better way to add a column to a data frame when calculating the new column requires more than one conditional. For example, if I wanted to associate a character string in {"Pos","Neg","Zero"} with each number in the following data frame: > d <- data.frame(num = -2:2) > d num 1 -2 2 -1 3 0 4 1 5 2 I
2009 Nov 06
3
Calculate Mean for each Treatment/Trial Interaction in DF
Hi, I am create a new DF that summarizes the mean angle per treatment/trial, of the original DF (see below). I have had some success using: (tapply(df$Angle, INDEX=interaction(df$State, df$Trial), FUN=mean)); however, this gives the answer as a list, which means I would have to split the name to get the categories back. Does anyone know a simple way to transform the Original DF into Summary
2009 Feb 10
0
Dataframes: conditional calculations per row [SOLVED].
> Thank you very much Jorge, Phil and David: I was finally able to > perform the operations I needed. I changed the function in order to > adapt it to the simplest form like the following: > ali <- function(Abase) { > alitemp <- ((Abase/llmcc$Clase)*PClase)+(((1/llmcc > $Categoria)*Abase)*PCategoria)+((Abase*llmcc$Phi)*PPhi)+((Abase*llmcc > $Rf)*PRf) >
2008 Jul 03
3
Recoding a variable
Hi All, I'm relatively new to R. I have a variable, "internet use," which ranges from "Almost everyday, "Several times a week," "Several times a month," "Seldom," "Never," and "Don't know." I want to recode this data into a new variable, say "use.internet," such that I have a dichotomous variable indicating
2008 Sep 11
3
Calculate mean/var by ID
Hello, I have a data set that looks like this. ID value 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the mean and var for each object identified by the ID. I can in theory just loop through the whole thing..., but is there a easier way/command which let me calculate the mean/var by ID? Thanks, Julia -- View this
2005 Apr 03
2
how to draw a 45 degree line on qqnorm() plot?
# I can not draw a 45 degree line on a qqnorm() plot, jj <- sample(c(1:100), 10) qqnorm(jj) abline() don't work. Thank you.
2011 Dec 05
2
class extension and documentation
I've added a "backsolve" method to the bdsmatrix library. Per the Extending manual section 7.1 I've also added the following 3 lines along with my setMethod definitions for 2 classes. backsolve <- function(r, ...) UseMethod("backsolve") backsolve.default <- base:::backsolve formals(backsolve.default) <- c(formals(backsolve.default), alist(... = )) I've
2011 Oct 10
2
tapply
Hola Estoy cometiendo un error con tapply (lógicamente acepto cualquier otra forma para mi problema). Prepare el siguiente código para copiar y pegar, donde describo los datos y mi problema, creo que es la forma más fácil de explicarme. # primero cargo los datos para explicar el problema individuo <- c(''a'', ''b'', ''c'',
2023 Nov 06
0
I need to create new variables based on two numeric variables and one dichotomize conditional category
Avi: Thank you for checking. I think the optimization is limited. If test is all TRUE or all FALSE then at most one vector is evaluated. Anything beyond that would be very complicated. (Inspect the two expressions and verify that both specify elementwise computations. Then use indexing to shrink the input properly. Take into account all recycling rules for binary operations.) > ifelse(0:1,
2008 Dec 23
6
Interval censored Data in survreg() with zero values!
Hello, I have interval censored data, censored between (0, 100). I used the tobit function in the AER package which in turn backs on survreg. Actually I'm struggling with the distribution. Data is asymmetrically distributed, so first choice would be a Weibull distribution. Unfortunately the Weibull doesn't allow for zero values in time data, as it requires x > 0. So I tried the
2010 Feb 22
2
how do I calculate means or cov matrix for multivariate groups
Hello, Having the matrix d > d value value2 class 1 1 1 x 2 2 2 x 3 3 3 x 4 4 2 x 5 5 1 y 6 11 3 y 7 12 4 z 8 13 5 z 9 14 6 z 10 15 7 z I want to calculate the means and cov matrix for groups x,y,z. I know how to do it the long way. I tried to use tapply and
2006 Aug 02
2
best way to calculate per-parameter differences in across-subject means
Hello, I have some data in a data.frame where for each of a number of subjects, I have scores for all of a number of symptoms. Subjects are subdivided in a number of groups, which have unequal sizes. I'd like to plot between-group differences in the scores on the various symptoms. Ideally, that would be in a form as would be produced by > bwplot( Score~Symptom ) but I'm not sure
2009 Sep 03
2
dividing a dataframe column by different constants
Dear R users, today I've got the following problem. Here you are a dataframe as example. There are some SAMPLES for which a CONCentration was recorded through TIME. The time during which the concentration was recorded is not always the same, 10 points for Sample A, 7 points for Sample B and 11 for sample C Also the initial concentration was not the same for the three samples. I would like