Displaying 20 results from an estimated 8000 matches similar to: "cumulative sum of within levels of a dataframe"
2008 Mar 31
1
adding device size-independent y=0 line to a lattice plot
Using the following lattice plot as an example, I would like to add
horizontal lines where y=0:
library(lattice)
library(grid)
fac <- gl(4,12)
x <- letters[rep(1:3,16)]
y <- runif(48,min=0.0)
dotplot(y~x|fac)
I've tried it with grid.lines using npc and native units, which works
fine unless I change the size of the output device - then the lines
are in the wrong place. Is there a
2005 May 24
1
Contingency tables from data.frames
Dear list,
I'm trying to do a set of generic functions do make contingency tables from
data.frames. It is just running "nice" (I'm learning R), but I think it can be
better.
I would like to filter the data.frame, i.e, eliminate all not numeric variables.
And I don't know how to make it: please, help me.
Below one of the my functions ('er' is a mention to EasieR,
2008 Jan 05
2
Cumulative sum of vector
Hi,
Maybe I have not been looking in the right spot, but, I have not been
able to fine a command to automatically calculate the running
cumulative sum of a vector. Is there such a command?
Example of current code:
> eig$values
[1] 678.365651 6.769697 2.853783
> prop<-eig$values/sum(eig$values)
> prop
[1] 0.986012163 0.009839832 0.004148005
>
2009 Jun 17
2
cumulative sum in data frame
Dear R-Help List,
I have a question about data manipulation. I tried to make code myself but too much for me. I would greatly appreciate your help.
I have data set consisting of site (from 1 to N1) and distance and there are several variables (1 to N2) collected from each sampling site. I am interested in looking at cumulative sums of each variable based on site and distance like below.
Can
2009 Feb 12
3
getting all pairwise combinations of elements in a character string
I'm able to do this as follows, but am wondering if anyone knows a
simpler way which still avoids explicit loops?
> (mystring <- letters[1:5])
[1] "a" "b" "c" "d" "e"
> unlist(sapply(mystring[-length(mystring)],
+ function(x)
paste(x,mystring[(grep(x,mystring)+1):length(mystring)],sep="")))
a1 a2 a3
2011 Dec 07
1
data frame and cumulative sum
Hello,
I have a data frame that looks like this (containing interarrival times):
> str(df)
'data.frame': 18233 obs. of 1 variable:
$ Interarrival: int 135 806 117 4 14 1 9 104 169 0 ...
> head(df)
Interarrival
1 135
2 806
3 117
4 4
5 14
6 1
>
This corresponds to the time differences (in ms) of a poisson arrival
2012 Jan 27
1
Conditional cumulative sum
Dear List,
I'll appreciate your help on this. I'm trying to create a variable as in
"cumsum_y.cond1" below, which should compute the cumulative sum of "y"
conditional on the value of cond==1.
set.seed(1)
d <- data.frame(y= sample(c(0,1), 10, replace= T),
cond= sample(c(0,1), 10, replace= T))
y cond cumsum_y.cond1
1 0 0 0
2 0 0
2009 Aug 27
2
setting par(srt) according to plot aspect ratio
How can I look up the aspect ratio of a plot, so I can use that to correctly
adjust the angle of text which is supposed to be parallel to a line in the
plot?
The following example code works for a 1:1 aspect ratio, but puts the text
at the wrong angle if the plot region is short and wide or tall and narrow.
I can't find a par() component containing the plot aspect ratio. It will
be for
2008 Mar 31
1
mean vs sum behavior
Dear all
Could someone explain me why
lapply(split(x,fac),mean)
returns means per levels of fac for each column of x
whereas
lapply(split(x,fac),sum)
does not return sums per level of fac and columns of x, but adds all
columns together?
Hence, how can I get sum to behave as mean in this instance?
Thank you very much in advance
E. Castella
2009 Aug 31
3
Two way joining vs heatmap
Hi
STATISTICA has a function called "Two-way joining" (see
http://www.statsoft.com/TEXTBOOK/stcluan.html#twotwo) and the
reference material states that this is based on the method as
published by Hartigan (found this paper:
http://www.jstor.org/pss/2284710 through wikipedia).
What is the relationship (if any) between the "heatmap" function in R
and this technique? Is there an
2013 Mar 26
2
Plot cumulative sums of rainfall per year
Hi @all,
I am biting my nails with the following problem:
I have a data set of daily rainfall measurements for the last 20 years. What I want to do is calculate the daily cumulative sum of rainfall but only for every year which means that the cumulative sum has to be reset each year. After the calculations I want to plot each year of cumulative rainfall as a separate line in one graph preferably
2005 Jul 07
1
Tables: Invitation to make a collective package
Hi All,
I would like to make an invitation to make a collective package with all
functions related to TABLES.
I know that there are many packages with these functions, the original idea is
collect all this functions and to make a single package, because is arduous for
the user know all this functions broadcast in many packages.
So, I think that the original packages can continue with its
2009 Feb 12
3
Looping multiple output values to dataframe
Dear R users,
I have various vector geometry operations to perform on 3-D coordinate data
located on multiple (500+) csv files. The code I have written for the
calculations works just fine. I have written a 'for' loop to automate the
task of extracting the coordinates from the files and perform the analyses.
The loop works reasonable well, but if the number of csv files is greater
than
2009 Dec 16
1
difference between the meaning of MARGIN in sweep() and apply()
For example, subtracting 1:2 from the rows of a two-column matrix:
> t(apply(matrix(1:6,ncol=2),MARGIN=1,function(y) y - 1:2))
[,1] [,2]
[1,] 0 2
[2,] 1 3
[3,] 2 4
> sweep(matrix(1:6,ncol=2),MARGIN=2,1:2,FUN="-")
[,1] [,2]
[1,] 0 2
[2,] 1 3
[3,] 2 4
Is there a logic to this difference, or is it just a quirk of the history of
these
2008 Mar 23
3
"spreading out" a numeric vector
I am creating a timeline plot, but running into a problem in positions
where the values to plot are too close together to print the text
without overlap. The simplest way I can think of to solve this
(although there may be other ways?) is to create a new numeric vector
whose values are as close as possible to the original vector, but
spread out to a given minimum difference. For example, take
2009 Jul 28
1
Cumulative row sums, row differences
I tried searching but I couldn't quite find what I was looking for.
Here's a dummy data matrix (with row and column labels):
> y
0 1 2 3 4
21 3 4 8 5 5
22 3 6 8 6 NA
23 4 5 11 4 3
24 4 2 1 4 6
25 6 4 4 6 6
I can get cumulative row sums as follows:
> cy<-t(apply(y,1,cumsum))
> cy
0 1 2 3 4
21 3 7 15 20 25
22 3 9 17 23 NA
23 4 9 20 24 27
24 4 6 7 11 17
2005 Feb 10
5
Annual cumulative sums from time series
Hello world,
I am actually transferring a course in data management for
students in biology, geography and agriculture
from statistica to R - it works
surprisingly well. If anyone is interested in my scratch/notepad
(in German language), please see
www.hydrology.uni-kiel.de/~schorsch/statistik/statistik_datenauswertung.pdf
(pages 40-52)
The dataset is:
2013 Dec 14
2
Change factor levels
Suppose I have a dataframe 'd' defined as
L3 <- LETTERS[1:3]
d0 <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace
= TRUE))
(d <- d0[d0$fac %in% c('A', 'B'),])
x y fac
2 1 2 B
3 1 3 A
4 1 4 A
5 1 5 A
6 1 6 B
8 1 8 A
Even though factor 'fac' in 'd' only has 2 levels, but it seems to bear the
birthmark
2010 Apr 14
5
Running cumulative sums in matrices
Dear R-helpers,
I have a huge data-set so need to avoid for loops as much as possible. Can someone think how I can compute the result in the following example (that uses a for-loop) using some version of apply instead (or any other similarly super-efficient function)?
example:
#Suppose a matrix:
m1=cbind(1:5,1:5,1:5)
#The aim is to create a new matrix with every column containing the
2008 Mar 05
2
differentiating a numeric vector
What functions exist for differentiating a numeric vector (in my case
spectral data)? That is, experimental data without an analytical
function. ie,
> x <- seq(1,10,0.1)
> y=x^3+rnorm(length(x),sd=0.01) #although the real function would be nothing simple like x^3...
> derivy <- ....
I know I could just use diff(y) but it would be nice to estimate
derivatives at the