Displaying 20 results from an estimated 10000 matches similar to: "plyr and table question"
2008 Dec 10
4
tapply within a data.frame: a simpler alternative?
Dear list,
I have a data.frame with x, y values and a 3-level factor "group",
say. I want to create a new column in this data.frame with the values
of y scaled to 1 by group. Perhaps the example below describes it best:
> x <- seq(0, 10, len=100)
> my.df <- data.frame(x = rep(x, 3), y=c(3*sin(x), 2*cos(x),
> cos(2*x)), # note how the y values have a different
2008 Jul 25
3
melting a list: basic question
Dear list,
I'm trying to use the reshape package to perform a merging operation
on a list of data.frames as illustrated below,
> a <- 1:10
> example <- list( data.frame(a=a, b=sin(a)), data.frame(a=a,
> b=cos(a)) )
>
> melt(example, id = a)
this produces the desired result, where the data.frames have been
coerced into one with a common identifier variable
2008 Aug 09
2
levels values of cut()
Dear list,
I have the following example, from which I am hoping to retrieve
numeric values of the factor levels (that is, without the brackets):
>
> x <- seq(1, 15, length=100)
> y <- sin(x)
>
> my.cuts <- cut(which(abs(y) < 1e-1), 3)
> levels(my.cuts)
hist() does not suit me for this, as it does not necessarily respect
the number of breaks.
getAnywhere
2008 Oct 05
1
plyr package: passing further arguments fail
Dear list and Hadley,
The new plyr package seems to provide a clean and consistent way to apply a function on several arguments. However, I don't understand why the following example does not work like the standard mapply,
library(plyr)
df <- data.frame(a=1:10 , b=1:10)
foo1 <- function(a, b, cc=0, d=0){
a + b + cc + d
}
mdply(df, foo1, cc=1) # fine
mdply(df, foo1, d=1) #
2009 Apr 16
3
segment between points on different plots
Hi,
I need to draw a line segment between two points on different plots in the
same multigraph.I've tried looking at the zoominplot function in plotrix but
havent understood much.any help is appreciated
~Aks
[[alternative HTML version deleted]]
2008 Dec 02
1
legend idea for latticeExtra
Dear list,
I've written a small utility function to add arbitrary legend(s) to a
lattice graph (or a combination of them), much like the legend
function of base graphics. I though perhaps it could be useful to
someone else, or improved by suggestions. I understand this goes
against the lattice paradigm somewhat, in that you short-cut the link
between group variables and the
2008 Jun 18
2
highest eigenvalues of a matrix
DeaR list,
I happily use eigen() to compute the eigenvalues and eigenvectors of
a fairly large matrix (200x200, say), but it seems over-killed as its
rank is limited to typically 2 or 3. I sort of remember being taught
that numerical techniques can find iteratively decreasing eigenvalues
and corresponding orthogonal eigenvectors, which would provide a nice
alternative (once I have the
2008 May 23
2
[slightly off topic] Sweave with markdown
DeaR list,
Has anyone tried to mix the Sweave paradigm with the Markdown[*] (and
co.) syntax? Would this be hard to implement? My tiny understanding
of Sweave is that one can define new drivers for the text part, while
some functions that deal with the R code would not require any
modification. Here's the reason I'm interested in Mardown for a driver.
I've been orbiting
2009 Mar 09
3
How to write a function that accepts unlimited number of input arguments?
Dear R-helpers:
I am an R newbie and have a question related to writing functions that
accept unlimited number of input arguments.
(I tried to peek into functions such as paste and cbind, but failed, I
cannot see their codes..)
Can someone kindly show me through a summation example?
Say, we have input scalar, 1 2 3 4 5
then the ideal function, say sum.test, can do
2008 Dec 11
3
generate combination multiset (set with repetition)
Hi,
This has been asked before but not sufficiently answered from what I
could find. How do you create combinations
with repetitions (multisets) in R?
If I have
> set <- array(1:3)
And I want to choose all combinations of picking 2 numbers, I want to
get a print out like
[,1] [,2]
[1,] 1 1
[2,] 1 2
[3,] 1 3
[4,] 2 2
[5,] 2 3
[6,] 3 3
subsets(set,
2008 Jul 03
1
ggplot2 legend for vertical lines
Dear all,
The following example code produces a graph with ggplot2, to which I
add several vertical lines of arbitrary colors. I am not satisfied
with the legend: it automatically adds some vertical lines which I'd
rather not see (they confuse the reader rather than add information
in this case).
> library(ggplot2)
> dfr <- data.frame(values = sin(1:50/10),
> fact =
2008 Apr 12
1
lm() of one matrix against another
Hello R list,
I have two matrices of identical dimensions, and I want to fit a
straight line for each pair of columns and plot the resulting lines.
I got it to work with a for loop, but there must be a better way,
> n<-5
> N<-10
>
> data.x<-matrix(1:(n*N),ncol=n)
> data.y<-matrix(1:(n*N) + rnorm(n*N,sd=1),ncol=n)
>
>
2008 Apr 26
6
quasi-random sequences
Dear list useRs,
I have to generate a random set of coordinates (x,y) in [-1 ; 1]^2
for say, N points. At each of these points is drawn a circle (later
on, an ellipse) of random size, as in:
> N <- 100
>
> positions <- matrix(rnorm(2 * N, mean = 0 , sd= 0.5), nrow=N)
> sizes<-rnorm(N, mean = 0 , sd= 1)
> plot(positions,type="p",cex=sizes)
My problem is to
2009 Apr 14
2
subset dataframe by rows using character vector?
Dear List,
I'm stuck on what seems like a simple indexing problem, I'd be very grateful to anyone willing to help me out.
I queried a dataframe which returns a character vector called "plot". I have another dataframe from which I want to subset or select only those rows that match "plot". I've tried subset, and also the "which" command.
plot
2008 Feb 14
1
write output in a custom format
Hi,
I need to create a text file in the following format,
> 1 100.0 0
> 0 0
> 1 1
> 0 0
> 1 1
> #
> 1 100.0 0
> 0 0
> 0 1
> 1 0
> 1 1
...
where # is part of the format and not a R comment.
Each block (delimited by #) consists of a first line with three
values, call it dose, and a list of (x,y) coordinates which are a
matrix or data.frame,
>
2009 Mar 31
5
Using apply to get group means
Hi all,
I'm trying to improve my R skills and make my programming more efficient and succinct. I can solve the following question, but wonder if there's a better way to do it:
I'm trying to calculate mean by several variables and then put this back into the original data set as a new variable. For example, if I were measuring weight, I might want to have each individual's
2007 Dec 28
1
unit attribute to list elements
Hi,
I've started my own (first) package, part of which consists in
listing common physical constants (Planck's constant, the speed of
light in vacuum, etc). I'm wondering what would be a good way of
dealing with pairs of value/unit.
> constants <- list( cel = 2.99792458e8 , #m/s
> Z0 = 376.730313461, #ohm
> eps0 = 8.854187817e-12,#F/m
> mu0 = 4*pi*1e-7,#N/A^2
2009 May 31
2
grid.edit() for ggplot2
Dear all,
I'm trying to access and modify grobs in a ggplot2 plot. The basic
idea for raw Grid objects I understand from Paul Murrell's R graphics
book, or this page of examples,
http://www.stat.auckland.ac.nz/~paul/grid/copygrob/copygrobs.R
However I can't figure out how to apply this to a ggplot (basically I
don't know how to write a syntactically correct gPath),
p
2008 Dec 01
2
align two lattice plots with grid
Dear list,
I need to align two plots on top of each other for comparison (they
only have the x-axis in common). When the y-labels have a different
extent, I cannot find a way to align the x-axes, as illustrated below,
> library(grid)
> library(lattice)
> x <- seq(0, 10, length=100)
> y <- sin(x)
> y2 <- 10*sin(x)
> f <- rep(c("1", "2"),
2008 Aug 07
2
lattice: add vertical lines in xyplot
Hi list,
This is a very basic question about lattice: I wish to add some
vertical lines in each panel of a xyplot as demonstrated in this
example:
> library(lattice)
>
> xx <- seq(1, 10, length=100)
> x <- rep(xx, 4)
> y <- c(cos(xx), sin(xx), xx, xx^2/10)
> fact <- factor(rep(c("cos", "sin", "id", "square"), each=100))