similar to: adding labels to tapply results

Displaying 20 results from an estimated 50000 matches similar to: "adding labels to tapply results"

2008 Sep 28
2
using tapply on a data frame in a function
Hello, I'm trying to use tapply to find group means in a function. It works outside of a function, but I get the error message from the following code: "Error in tapply(index, cluster, mean) : arguments must have same length." Any suggestions? Thanks. eric d <- data.frame(cbind(cluster=1:2, value1=1:10, value2=11:20)) d FindClusterTraits <- function(framename, index){
2011 Jan 31
1
arranging pie charts in a matrix layout with row/col labels
Hi, I have a vector of data, that I group based on two factors via tapply. For each such grouping I would like to plot a pie chart. I can layout these pie charts in a matrix layout, correpsonding to the levels of the two factors. But I am getting stuck on how to label the rows and colums. My current approach looks like this: x <- data.frame(obs=sample(c('low', 'high'),100,
2007 Jan 26
1
plotting results from tapply
Hi, there I'm trying to plot what is returned from a call to tapply, and can't figure out how to do it. My guess is that it has something to do with the inclusion of row names when you ask for the values you're interested in, but if anyone has any ideas on how to get it to work, that would be stellar. Here's some example code: y1<-rnorm(40, 2) x1<-rep(1:2, each=20)
2012 Sep 03
1
Scatter plot from tapply output, labels of data
Hei, i am trying to plot the means of two variables (d13C and d15N), by 2 grouping factors (Species and Year) that i obtained by the function tapply. I would like to plot with different colours according to the Year and show the "Species" as data labels. My data looks like this: Species d13C d13N Year "Species1" 14,4 11.5 2009 "Species2"
2008 Aug 01
3
Newbie question: How to use tapply() on several vectors simultaneously
Dear R users, I have a newbie-question that I couldn't resolve after reading through several pieces of documentation and searching the archive. I have a data.frame containing experimental data from a group experiment in psychology. Each line represents a single participant, but participants were assigned to groups of three or four persons. One variable indicates each participants'
2012 Sep 15
2
How to convert the output of tapply() so that it has the same order as the input?
Hi, I try to apply a function to subsets of a data.frame. tapply() does the job, but the as output, I am looking for a vector (not an array/matrix) ordered in the same way as the original data, so I can simply cbind the result to the original data.frame. Below is a minimal example. I know that there are packages that can do these things easier, but I'm looking for a fast solution not
2005 Feb 03
2
Surprising Behavior of 'tapply'
Dear all, I wanted to make a two-way-table of two variables with a counting variable stored in another column of a dataframe. In version 1.9.1, the behavior is as expected as shown in the simplified example code. > sex <- rep(c("F", "M"), 5) > income <- c(rep("low", 5), rep("high", 5)) > count <- 1:10 > mydf <-
2008 Oct 29
2
Help using tapply with multiple variables
Dear list, I have the function (as a simple example, which is actually part of a larger function) pres.test<-function(N0=N0, N1=N1) { dt<-5 r<-log(N1/N0)/dt r } which calculates the annual growth rates in a population Where N0 is the population classified into age intervals, say 5 years, at time=1995, and N1 is the population by 5 year age classes at time=2000.
2009 Jun 16
2
tapply with cbinded x
Dear List, why does this not work? df <- data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), fac = c('A', 'A', 'B')) tapply(cbind(df$var1, df$var2, df$var3), df$fac, mean) Thank you, Stefan
2007 Oct 05
4
Replacing NA values when building matrix using tapply
Hi, I'm building a matrix m from a data frame d which includes the matrix row, column and value. This works well enough: m <- tapply(d[,"value"],d[,c("row","column")],c) However, I'd like to replace any missing values with 0, not NA. The obvious doesn't work, however: m <-
2004 Aug 03
2
attach data from tapply to dataframe
I am working with a longitudinal data set in the long format. This data set has three observations per grade level per year. Here are the first 10 rows of the data frame: >tenn.dat[1:10,] year schid type grade gain se new cohort 6 2001 100005 5 4 33.1 3.5 4 3 7 2002 100005 5 4 33.9 3.9 4 2 8 2003 100005 5 4 32.3 4.2 4 1 10 2001 100005
2007 Nov 28
1
interaction of shingles and tapply()
I'm interested in a version of tapply() that operates with shingles instead of factors. For instance: x <- c(1,1,2,2,3,3) y <- c(1,1,1,0,0,0) s <- shingle(x,intervals=cbind(c(0.5,1.5),c(2.5,3.5))) # the following function should exist! tapply.shingle(x,s,mean) # returns the vector c(0.75,0.25) I've written such a function as follows: tapply.shingle <-
2005 May 25
2
weighted.mean and tapply (again)
I read answers to questions including the words "tapply" and "weighted.mean", but I didn't understand either the problem (data) or the solution provided. Here is my question ... > dat[1:10,] GROUP VALUE FREQUENCY 1 2 2 78 2 2 3 40 3 2 4 16 4 2 5 3 5 2 6 1 6 2 8 1 7
2001 Feb 21
1
Specification of factors in tapply
After some fiddling around with the tapply command, I discovered that the factors (the INDEX argument) given to tapply must be specified in fastest-cycling first order. The following code shows how I discovered my error: (R version 1.2.1) -o-o-o-o-o- x <- as.data.frame(list(data=c(-9,0,3,1,-9,1,0,-9,0,3,1,-9,1,0), subj=c(rep(1,7),rep(2,7)),
2005 Jul 05
1
by (tapply) and for loop differences
I am getting a difference in results when running some analysis using by and tapply compare to using a for loop. I've tried searching the web but had no luck with the keywords I used. I've attached a simple example below to illustrates my problem. I get a difference in the mean of yvar, diff and the p-value using tapply & by compared to a for loop. I cannot see what I am doing wrong.
2008 Dec 11
1
How do I tapply to a data frame with arbitrary column labels?
I have a data file that looks like this class pigeon falcon propeller jet wing fly birds 25 37 0 0 2 1 planes 0 1 28 40 1 3 birds 19 41 0 1 4 6 planes 0 0 25 50 5 5 planes 1 0
2007 Jan 17
1
tapply, data.frame problem
Hi R-users, I'm quite new to R and trying to learn the basics. I have a following problem concerning the convertion of array object into data frame. I have made following data sets tmp1 <- rnorm(100) tmp2 <- gl(10,2,length=100) tmp3 <- as.data.frame(cbind(tmp1,tmp2)) tmp3.sum <- tapply(tmp3$tmp1,tmp3$tmp2,sum) tmp3.sum <- as.data.frame(tapply(tmp1,tmp2,sum)) and I want the
2006 Jul 06
2
tapply question
I think I understand tapply but i still can't figure out how to do the following. I have a dataframe where some of the column names are the same and i want to make a new dataframe where columns that have the same name are averaged by row. so, if the data frame, DF, was AAA BBB CCC AAA DDD 1 0 7 11 13 2 0 8 12 14 3 0 6 0 15
2003 Jul 31
1
help with tapply and weighted.mean
Hello! I have data frame with 'weights' in one of the columns. I need to compute weighted mean on another column other factor variable and i am trying to: res<-tapply(data$k,list(data$model),weighted.mean,w=data$w,na.rm=T) and i get: Warning messages: 1: longer object length is not a multiple of shorter object length in: x * w 2: longer object length is not a multiple of shorter
2009 Jul 08
2
Two-way ANOVA gives different results using anova(lm()) than doing it by hand
Hey! Could you please take a quick look at what I have done? Somehow I get wrong results using the anova(lm()) combination compared to doing a two way ANOVA by hand. Running: Data<-read.table("Data.txt"); g<-lm(ExM~S1*S2,Data); anova(g); Gives: Analysis of Variance Table Response: ExM Df Sum Sq Mean Sq F value Pr(>F) S1 1 4.3679