Displaying 20 results from an estimated 4000 matches similar to: "Find the first values in vector"
2009 Jun 01
2
add values inside vector
I think it's easy problem but I can't find solution.
I have a vector:
vec <- c (23.4, 3.0, 14.7, 7.7)
and I would like to add all values which are inside my vector to each
other.
as a result a want to get one value like sum all values from my vector-
sth=(23.4 + 3.0 + 14.7 + 7.7)
PS. I usually don't know how long is my vector in my function
--
View this message in
2009 Aug 23
2
difficult "for"
Hi,
My english isn't brilliant and my problem is very difficult to describe but
I try ;)
My first question is: May I write loop "for" like this or similar - for (i
in sth : sth[length(sth)], k in sth_else : length(sth_else) ) - I'd like
to have two independent conditions in the same loop "for".
My secound question depend on program below. I'd like to write every
2009 Jun 01
3
Editor R
Do you know any good editor R?
--
View this message in context: http://www.nabble.com/Editor-R-tp23822342p23822342.html
Sent from the R help mailing list archive at Nabble.com.
2009 Aug 30
1
about isoMDS method
Hi,
For example:
I built a half matrix "w" using a daisy(x, metric = c("euclidean"))
http://www.nabble.com/file/p25211016/1.jpg
And next I transformed this matrix "w" using isoMDS function, for example
isoMDS(w, k=2) and as result I got:
http://www.nabble.com/file/p25211016/2.jpg
And now I have two questions:
1. If number in matrix w[2, 1] (= 0.41538462) match
2009 Sep 06
2
avoid NA in list
Hi!
I have list, for example:
...
[[22]]
[1] 27 51 69 107 119
[[23]]
[1] NA
[[24]]
[1] 54 57 62
And I would like to avoid NA value. Similar way like I may do it in vector
using na.value() function.
Do you have any idea?
--
View this message in context: http://www.nabble.com/avoid-NA-in-list-tp25321020p25321020.html
Sent from the R help mailing list archive at Nabble.com.
2009 Nov 10
1
write data frame in a list
Hi,
I have got a data frame:
df=data.frame(x=c(3,6,7),y=c(2,7,4))
and I would like to write my values from data frame to list using loop, for
example:
lista=list()
for (i in 1: length(?)){
lista[[?]][?] = df [?]
}
But I havn't got any idea what I should put in places where I put a question
mark?
As a rusult I would like to get a list like this:
list:
[[1]]
3,6,7
[[2]]
2,7,4
I
2008 Jan 13
3
product of vector elements
All,
I would like to find a simper method that I now have to find the
product of all elements in a vector:
#get product of vector elements: (1,2,3,4,5)
vec.product <- exp(sum(log(c(1,2,3,4,5))))
I have not found a vector product function, if one has been written.
Thanks,
Gerard
[[alternative HTML version deleted]]
2010 Apr 08
1
Question on using elements of a vector
Hi
So my particular problem is this:
I have a row vector of length 5200 elements - specifically created by
x<-rbinom(5200,1,0.5)
y<-matrix(x,nrow=1,ncol=5200)
y
now, each element is either a 0 or a 1 - e.g. it could be (0,1,1,1,1,0,0,0,1,1,1) e.t.c.
when the element is a 1, i need to multiply a number (say 1000) by 1.005, and if it is 1 again, multiply it _again_ by 1.005.
so
2009 Sep 06
1
Two packages and one method
Hi!
I want to use one method "combinations" from "gtools" package but in my code
I must use also "dprep" method where is method "combinations" too. Mayby I
show you result my help function:
Help on topic 'combinations' was found in the following packages:
Package Library
dprep /usr/lib64/R/library
gtools
2008 Aug 18
2
matrix row product and cumulative product
I spent a lot of time searching and came up empty handed on the
following query. Is there an equivalent to rowSums that does product or
cumulative product and avoids use of apply or looping? I found a rowProd
in a package but it was a convenience function for apply. As part of a
likelihood calculation called from optim, I?m computing products and
cumulative products of rows of matrices with
2011 Nov 27
1
generating a vector of y_t = \sum_{i = 1}^t (alpha^i * x_{t - i + 1})
Dear R-help,
I have been trying really hard to generate the following vector given
the data (x) and parameter (alpha) efficiently.
Let y be the output list, the aim is to produce the the following
vector(y) with at least half the time used by the loop example below.
y[1] = alpha * x[1]
y[2] = alpha^2 * x[1] + alpha * x[2]
y[3] = alpha^3 * x[1] + alpha^2 * x[2] + alpha * x[3]
.....
below are
2003 Mar 22
1
cumprod doesn't work with data frames (PR#2667)
Full_Name: J. Sisk
Version: 1.6.1
OS: Linux (RedHat 8)
Submission from: (NULL) (67.119.41.66)
Suppose you make a data-frame like so:
xxx <- data.frame(a=10,b=20,c=30,d=40)
Then
cumprod(xxx[1,])
returns
> cumprod(xxx[1,])
a b c d
1 10 20 30 40
The documentation for cumprod says that it should work on "numerical objects",
and this is a data-frame, but it
2006 Feb 28
2
vector math: calculating a rolling 12 row product?
I have a dataframe of numeric values with 30 ?rows?
and 7 ?columns?.
For each column, beginning at ?row? 12 and down to
?row? 30, I wish to calculate the ?rolling 12 row
product?. I.e., within each column, I wish to
multiply all the values in row 1:12, 2:13,
19:30.
I wish to save the results as a new dataframe, which
will have 19 rows and 7 columns.
2009 Sep 16
2
Generalized cumsum?
Is there anything like cumsum and cumprod but which allows you to
apply an arbitrary function instead of sum and product? In other words,
I want a function cumfunc(x, f) that returns a vector, so that for all n
up to the length of x
cumapply(x,f)[n] = f(x[1:n])
This would give cumsum and cumprod as special cases when f=sum or
f=prod.
I could write such a function, but I can't see
2011 Jan 27
1
How do I fix this ?
Just when I think I'm starting to learn ....
Statement z1 works, statement z doesn't. Why doesn't z work and what do I do
to fix it ? Clearly the problem is with the first NA, but I would think it's
handled through the loop vectorization.
y1 <- rnorm(20, 0, .013)
y1
[1] -0.0068630836 -0.0101106230 -0.0169663344 -0.0066314769 0.0075063818
[6] -0.0033548024 0.0015647863
2009 Oct 13
7
lapply() reccursively
Hi all,
I was wondering whether it is possible to use the lapply() function
to alter the value of the input, something in the spirit of :
a1<-runif(100)
a2<-function(i){
a1[i]<-a1[i-1]*a1[i];a1[i]
}
a3<-lapply(2:100,a2)
Something akin to a for() loop, but using the lapply() infrastructure.
I haven't been able to get rapply() to do this.
The reason is that the "real"
2010 Jul 09
3
apply is slower than for loop?
I thought the "apply" functions are faster than for loops, but my most
recent test shows that apply actually takes a significantly longer than a
for loop. Am I missing something?
It doesn't matter much if I do column wise calculations rather than row wise
## Example of how apply is SLOWER than for loop:
#rm(list=ls())
## DEFINE VARIABLES
mu=0.05 ; sigma=0.20 ; dt=.25 ; T=50 ;
2006 Aug 31
2
cumulative growth rates indexed to a common starting point over n series of observations
What is the R way of computing cumulative growth rates given a series of
discrete values indexed .
For instance, given a matrix of 20 observations for each of 5 series (zz),
what is the most straight forward technique in R for computing cumulative
growth (zzcum) ?
It seems for the solution I'm after might be imbedding the following cum
growth rate calc as a function into a function call
2009 Jul 31
1
what meaning missing value True /False needed
This is my code i don't understand the error message:
library(rgenoud)
rm(list=ls())
set.seed(666)
#########################################################
# As a first step, it is assumed that all input parameters are independent of ageingĀ :
#########################################################
InputDim <-20
# Max number of ageings in the inputs
CPIRate <- rep(0.02 , InputDim )
#
2009 May 29
4
logical vector as a matrix
I have a vector like this:
h <- c(4, 6, NA, 12)
and I create the secound logical vector like this:
g <- c(TRUE, TRUE, FALSE, TRUE)
And my problem is that I would like to get a new "m" vector as a rasult "h"
and "g"( as dot-matrix printer) but with missed "NA" value, for example:
m = (4,6,12)
Do you have any idea?
--
View this message in