Displaying 20 results from an estimated 1000 matches similar to: "Avoiding a Loop?"
2005 Dec 08
3
Reshaping data
Dear all,
given I have data in a data.frame which indicate the number of people in
a
specific year at a specific age:
n <- 10
mydf <- data.frame(yr=sample(1:10, size=n, replace=FALSE),
age=sample(1:12, size=n, replace=FALSE),
no=sample(1:10, size=n, replace=FALSE))
Now I would like to make a matrix with (in this simple example)
10 columns (for the
2005 Feb 21
3
Sorting a matrix on two columns
Hello,
If a matrix with 5 columns has been defined and the first two columns
need to be sorted in ascending order, how can this be achieved whilst
ensuring the
other 3 columns data are in relative position to the sorted columns?
Glen Jones
[[alternative HTML version deleted]]
2009 Nov 25
5
How to sum only a few elements in a line
Hello,
I have a matrix with the numbers 0,1 and 9
I would like to write a function that could sum each line skiping everytime
a number 9 appears
for example
[0 1 0 1 1 9 1]
the sum would be 4.
However I cannot replace 9 by 0 otherwise after the sum is done I wouldn?t
be able to distiguish which ones were real zeros and which ones were nines
replaced by zero just to sum.
Thank you very much
--
2007 Jan 29
1
"Reversal" of Aggregation
Dear all,
given I have a data.frame in a format like this
mydf <- data.frame(age=rep(1:3,5),
year=c(rep(1996,3), rep(1997,3), rep(1998,3),
rep(1999,3), rep(2000,3)),
income=1:15)
mydf
Now I convert it to some 2D-frequency table like this:
mymatrix <- tapply(X=mydf$income, INDEX=list(mydf$age, mydf$year),
2010 Jun 02
3
writing a matrix in a file
Hi,
I want to write a matrix (n*m) in a file (Text file) such that the file
will be as Result file (below).
I use the below command but it write all numbers in one column,
> write(paste(matrixname),file="test.txt",append=TRUE)
how can I do this?
Result file:
5 5 -1 -1 -1 -1
8 8 2 7 6 5
6 6 8 2 7 5
Matrix:
[,1] [,2] [,3] [,4] [,5]
2005 Aug 17
2
power of a matrix
Dear all,
I have a population with three age-classes, at time t=0 the population
is:
n.zero <- c(1,0,0)
I have a transition matrix A which denotes "fertility" and "survival":
A <- matrix(c(0,1,5, 0.3,0,0, 0,0.5,0), ncol=3, byrow=TRUE)
To obtain the population at t=1, I calculate:
A %*% n.zero
To obtain the population t=2, I calculate:
A %*% (A %*% n.zero)
... and so
2005 Sep 19
6
Teaching R - In front of the computer?
Dear R-Users,
given you have been teaching R to students (grad level, mainly social
science background, no previous programming experience, 80% know SPSS),
what are your experiences concerning the style of teaching? Do you
prefer to stand in front of the class like in "normal" lectures and you
show them slides? Or do you you explain some concept (for example things
like
2004 Jul 22
3
Replace only Capital Letters
Dear All,
I have these data:
exampledata <- c("This is one item", "This is Another One", "And so is
This")
I would like to find each occurence of a blank space followed by a Capital
Letter and replace it by a blank space, a left curly brace, the respective
Capital Letter, and then a right curly brace.
I thought the following will do:
gsub(pattern = "
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 <-
2006 Jul 14
2
References verifying accuracy of R for basic statisticalcalculations and tests
Hi,
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Corey Powell
>
> Do you know of any references that verify the accuracy of R
> for basic statistical calculations and tests. The results of
> these studies should indicate that R results are the same as
> the results of other statistical packages to a certain number
> of decimal places on some benchmark
2005 Oct 27
3
outer-question
Dear all,
This is a rather lengthy message, but I don't know what I made wrong in
my real example since the simple code works.
I have two variables a, b and a function f for which I would like to
calculate all possible combinations of the values of a and b.
If f is multiplication, I would simply do:
a <- 1:5
b <- 1:5
outer(a,b)
## A bit more complicated is this:
f <-
2005 Oct 27
3
outer-question
Dear all,
This is a rather lengthy message, but I don't know what I made wrong in
my real example since the simple code works.
I have two variables a, b and a function f for which I would like to
calculate all possible combinations of the values of a and b.
If f is multiplication, I would simply do:
a <- 1:5
b <- 1:5
outer(a,b)
## A bit more complicated is this:
f <-
2009 May 14
3
memory usage grows too fast
Hi All,
I have a 1000x1000000 matrix.
The calculation I would like to do is actually very simple: for each row, calculate the frequency of a given pattern. For example, a toy dataset is as follows.
Col1 Col2 Col3 Col4
01 02 02 00 => Freq of ?02? is 0.5
02 02 02 01 => Freq of ?02? is 0.75
00 02 01 01 ?
My code is quite simple as the following to find the pattern ?02?.
2006 Mar 01
2
error: uninitialized constant
total rails nuby here. I have a table "thumbnails", hence the model
Thumbnail. I''m extending the Thumbnail class with a few constants
needed for thumbnail cropping:
class Thumbnail < ActiveRecord::Base
SOURCE_FILE_PATH = "path/to/source"
TARGET_FILE_PATH = "path/to/target"
TARGET_WIDTH = 100
TARGET_HEIGHT = 100
end
Now, in my controller
2005 Nov 23
2
Dancing lissajous
We can't post images here so I've put up a web page to show off a neat
little animation in R:
http://www.geocities.com/robsteele/
Adios!
2005 May 19
5
Arranging Plots
Dear all,
I'd appreciate any hints how to arrange some plots.
I have three plots. I would like to arrange them in the following order:
- Plot 1 and Plot 2 should be in the upper row
- Plot 3 should be in the lower row but centered in the middle.
I hope the following sketch will help understanding my problem
================
| === === |
|| P1| |P2 | |
|| | | | |
| === === |
2013 Jun 27
3
using "rollapply" to calculate a moving sum or running sum?
#using "rollapply" to calculate a moving sum or running sum?
#I am tryign to use rollapply to calcualte a moving sum? #I tried
rollapply and get the error message
#"Error in seq.default(start.at, NROW(data), by = by) :
# wrong sign in 'by' argument"
#example:
mymatrix <- ( matrix(data=1:100, nrow=5, ncol=20) )
mymatrix_cumsum <- ( matrix(data=NA, nrow=5,
2009 Jul 20
1
S4 method dispatch with inheritance
Hi,
I'm trying to create a new S4 class (myMatrix) which for now just
extends dgCMatrix (from package Matrix). Then I want to use "[" which is
defined in Matrix.
Out of the box with "[" (defined in Matrix) I lose the class information
and the result is an object of class dgCMatrix. If I specify a
"["-method for myMatrix, it is not used because a signature
2006 Apr 04
2
Selecting out certain values from a MATRIX
I have two objects, one matrix and one vector.
I want to use my vector to subset certain values out of my matrix.
For example:
I want to tell R, to select out all rows in myMatrix into a new myMatrix2 IF
that corresponding row is less than a 0.5 in myVector.
So:
myMatrix = a matrix of 8000 by 20
myVector = vector of 8000
myMatrix2 = a matrix of < 8000 by 20 (based on selection criteria in
2004 Nov 01
5
make apply() return a list
Hi,
I have a dataframe (say myData) and want to get a list (say myList) that
contains a matrix for each row of the dataframe myData. These matrices are
calculated based on the corresponding row of myData. Using a for()-loop to do
this is very slow. Thus, I tried to use apply(). However, afaik apply() does
only return a list if the matrices have different dimensions, while my
matrices have