similar to: How to calculate the stratified means in a data frame?

Displaying 20 results from an estimated 10000 matches similar to: "How to calculate the stratified means in a data frame?"

2010 Jun 09
4
question about "mean"
Hi there: I have a question about generating mean value of a data.frame. Take iris data for example, if I have a data.frame looking like the following: --------------------- Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2
2004 Aug 21
2
more on apply on data frame
Hi R People: Several of you pointed out that using "tapply" on a data frame will work on the iris data frame. I'm still having a problem. The iris data frame has 150 rows, 5 variables. The first 4 are numeric, while the last is a factor, which has the Species names. I can use tapply for 1 variable at a time: >tapply(iris[,1],iris[,5],mean) setosa versicolor virginica
2008 Aug 07
6
multiple tapply
Hi folk, I tried this and it works just perfectly tapply(iris[,1],iris[5],mean) but, how to obtain a single table from multiple variables? In tapply x is an atomic object so this code doesn't work tapply(iris[,1:4],iris[5],mean) Thanx and great summer holidays Gianandrea -- View this message in context: http://www.nabble.com/multiple-tapply-tp18868063p18868063.html Sent from the R help
2001 Feb 19
1
means by column after split
Colleagues ---------------------------------- System info: R version rw1020 on NT ESS using emacs ver. 20.4 ---------------------------------- I need to get the means for each column of a dataframe in the list created by splitting a data frame. At present, I am getting the mean of all columns in aggregate. The structure of the unsplit data is: > shuttle.tr1[1:10,] juliandate
2018 Mar 23
2
aggregate() naming -- bug or feature
In the examples below, the first loses the name attached by foo(), the second retains names attached by bar(). Is this an intentional difference? I?d prefer that the names be retained in both cases. foo <- function(x) { c(mean = base::mean(x)) } bar <- function(x) { c(mean = base::mean(x), sd = stats::sd(x))} aggregate(iris$Sepal.Length, by = list(iris$Species), FUN = foo) #>
2010 Dec 15
3
Applying function to a TABLE and also "apply, tapply, sapply etc"
Dear R-help forum members, Suppose I have a data-frame having two variables and single data for each of them, as described below. variable_1           variable_2         10                          20 I have written a function, say, 'fun' which uses input 10 and 20 and gives me desired result. fun = function(X, Y)          {          X + Y              #( I am just giving an example of
2018 Mar 23
1
aggregate() naming -- bug or feature
On Fri, Mar 23, 2018 at 6:43 PM, Rui Barradas <ruipbarradas at sapo.pt> wrote: > Hello, > > Not exactly an answer but here it goes. > If you use the formula interface the names will be retained. Also if you pass named arguments: aggregate(iris["Sepal.Length"], by = iris["Species"], FUN = foo) # Species Sepal.Length # 1 setosa 5.006 # 2
2013 Jan 16
4
Get a percent variable based on group
Dear all, I'd like to get a percentage variable based on a group, but without creating a new data frame. For example: data(iris) iris$percent <-unlist(tapply(iris$Sepal.Length,iris$Species,function(x) x/sum(x, na.rm=TRUE))) This does not work, I should have only three standard values, respectively for setosa, versicolor, and virginica. How can I do this? MANY THANKS, Karine
2012 Jun 11
1
saving sublist lda object with save.image()
Greetings R experts, I'm having some difficulty recovering lda objects that I've saved within sublists using the save.image() function. I am running a script that exports a variety of different information as a list, included within that list is an lda object. I then take that list and create a list of that with all the different replications I've run. Unfortunately I've been
2012 Aug 28
1
don't print object attributes
Dear all Suppose the object below: > require(Hmisc) > require(plyr) > x <- dlply(iris, .(Species), describe) How can I print the object without displaying the attributes? I inspected ?print and ?print.default with no luck. > x $setosa x[, "Sepal.Length"] n missing unique Mean .05 .10 .25 .50 .75 50 0 15 5.006 4.40 4.59
2006 Sep 25
2
Splitting a character variable into a numeric one and a character one?
Hi All, I have a data with a variable like this: Column 1 "123abc" "12cd34" "1e23" ... Now I want to do an operation that can split it into two variables: Column 1 Column 2 Column 3 "123abc" 123 "abc" "12cd34" 12 "cd34" "1e23" 1
2004 Nov 28
1
Could anyone help me reshape this "wide" data into "longitudinal" one? Thanks
Dear R people, I have a matrix like this: var1 var2 var3 var4 a1 7.1 7.2 8.1 8.2 a2 10.5 10.6 ... ... a3 b1 b2 b3 b4 c1 c2 ... The matrix row names are "a1", "a2", ...... and the matrix column names are "var1", "var2", "var3" and "var4". Now I want to reshape this data into a
2004 Oct 21
0
Hmisc: Using stratified weighted means (wtd.mean) within a function
Hello list, I have the following function which, as you can see, uses mean: meanratings <- round(apply(stack03[,c(102:121)],2,function(x) (tapply(x ,actcode, mean, na.rm=T))), digits=1) The above function yields the following output: q27a q27b q27c q27d q27e q27f q27g q27h q27i q27j q27k q27l q27m q27o q27p 1 7.8 8.1 7.7 7.9 7.9 NaN NaN 8.4 7.8 7.0 7.6 NaN NaN 7.1 6.0 2
2008 Oct 01
2
an unsophisticated question about recoding in a data frame with control structure if {}
Hello all, I apologize for a terribly simple question. I'm used to using Stata and am trying to `switch' over to R. I would like to recode a vector in a data frame when the value of it meets the following condition: if (dataframe$factor=='3'){dataframe$thevector<-(an arithmetic mean). What I would like to result is the creation of a new variable within the data frame for
2004 Oct 04
2
Help with Affymetrix data
I have CEL files from Affymetrix Mouse Array 430_2 and am trying to get the the individual PM intensities (11 per gene) for each sample. I would like to write out this into a tab delimited text file. Where am I stalling? This is what I've done: Change dir(to where CEL files are saved) Data <- ReadAffy() eset <- rma(Data) write.exprs(eset, file="mydata.txt") With this I am
2007 Aug 01
1
New R package sqldf
sqldf is an R package for running SQL select statements on one or more R data frames. It is optimized for convenience making it useful for ad hoc queries against R data frames. Given an SQL select statement whose tables are the names of R data frames it: - sets up the database (by default it transparently sets up an in memory SQLite database using RSQLite; however, MySQL via RMySQL, can be
2007 Aug 01
1
New R package sqldf
sqldf is an R package for running SQL select statements on one or more R data frames. It is optimized for convenience making it useful for ad hoc queries against R data frames. Given an SQL select statement whose tables are the names of R data frames it: - sets up the database (by default it transparently sets up an in memory SQLite database using RSQLite; however, MySQL via RMySQL, can be
2012 Dec 19
2
create stratified splits
Hi, I have a vector like: r <- runif(100) Now I would like to split r into 10 pieces (each with 10 elements) ? but the 'pieces' should be roughly similar with regard to mean and sd. what is an efficient way to do this in R? thanks!
2006 May 01
4
table of means/medians across bins used for a histogram
Hi I am trying to get a table of means of parameter 1 across BINS of parameter 2. I am working in proteomics and a sample of my data is as follows cluster-age clock-rate(evolutionary rate) scopclass 0.002 10 A 0.045 0.1 B 0.13 15 A 0.15 34 D .... .... ....
2010 Apr 04
2
calculating an interaction statistic from stratified data
Dear R community, I have data on beta&standard error (for the main effect of variable x), stratified by sex for my dataset. I wish to calculate the sex-interaction effect (as beta&se) from these two stratified datasets. Is there a package to do this? If not, any advice how to do it manually? Thank you very much and best regards, Georg. ************************ Georg Ehret, JHU,