Displaying 20 results from an estimated 10000 matches similar to: "summing items within a row"
2010 Aug 27
4
How to calc ratios base on current and previous row?
Hi all,
I want to calculate in each row a ratio based on number in the current row and the previous row.
Is there a way to do this without for-loops because that is extremely slow.
A B
[1] 2 2
[2] 2 3
[3] 4 5,5
...
B2 = A2 + 0.5*B1
Thanks in advance.
Best
Marcus
2005 Feb 15
1
matlab norm(h) command in R: sqrt(sum(h^2)) - use in an expression
Hi
in matlab I defined a function (double gamma, parameters at the end of
this mail) as
h(i)=((t/d1)^a1)*exp(-(t-d1)/b1)-c*((t/d2)^a2)*exp(-(t-d2)/b2);
h=h/norm(h);
I do know that norm() in matlab is equal to:
sqrt(sum(x^2))
in R
so in R I do it like:
#function (double gamama)
h <- expression((t/d1)^a1*exp(-(t-d1)/b1)-c*(t/d2)^a2*exp(-(t-d2)/b2))
# plot it
t <- seq(0, 20000,
2004 Sep 07
1
Contrast matrices for nested factors
Hi, I'd like to know if it's possible to specify different
contrast matrices in lm() for a factor that is nested within another one. This
is useful when we have a model where the nested factor has a different
number of levels, depending on the main factor.
Let me illustrate with an example to make it clearer. Consider
the following data set:
set.seed(1)
y <-
2009 Jan 23
1
Interpreting model matrix columns when using contr.sum
With the following example using contr.sum for both factors,
> dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) # balanced 2-way
> model.matrix(~ a * b, dd, contrasts = list(a="contr.sum", b="contr.sum"))
(Intercept) a1 a2 b1 b2 b3 a1:b1 a2:b1 a1:b2 a2:b2 a1:b3 a2:b3
1 1 1 0 1 0 0 1 0 0 0 0 0
2 1 1 0 0 1 0
2012 Sep 07
6
splitting character vectors into multiple vectors using strsplit
Hi folks,
Suppose I create the character vector charvec by
> charvec<-c("a1.b1","a2.b2")
> charvec
[1] "a1.b1" "a2.b2"
and then I use strsplit on charvec as follows:
> splitlist<-strsplit(charvec,split=".",fixed=TRUE)
> splitlist
[[1]]
[1] "a1" "b1"
[[2]]
[1] "a2" "b2"
I was wondering
2009 Nov 29
3
Plotting observed vs. Predicted values, change of symbols
Dear Wiz[R]ds,
I am deeply grateful for the help from Duncan Murdoch, Gray Calhoun, and
others. We are almost there. For whatever reason, I can't change the symbol
from a circle to a triangle in the upright posture plots. Any ideas? I have
included the problem in full.
# tritiated (3H)-Norepinephrine(NE) disappearance from plasma
# concentrations supine and upright
# supine
datasu <-
2003 Nov 18
1
aov with Error and lme
Hi
I searched in the list and only found questions
without answers e.g.
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/19955.html
: Is there a way to get the same results with lme as
with aov with Error()?
Can anybody reproduce the following results with lme:
id<-c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5)
2012 Apr 19
3
How to "flatten" a multidimensional array into a dataframe?
Hi,
I have a three dimensional array, e.g.,
my.array = array(0, dim=c(2,3,4), dimnames=list( d1=c("A1","A2"),
d2=c("B1","B2","B3"), d3=c("C1","C2","C3","C4")) )
what I would like to get is then a dataframe:
d1 d2 d3 value
A1 B1 C1 0
A2 B1 C1 0
.
.
.
A2 B3 C4 0
I'm sure there is one function to do
2013 Feb 23
1
how to calculate left kronecker product?
For an application, I have formulas defined in terms of a left Kronecker
product of matrices,
A,B, meaning
A \otimes_L B = {A * B[i,j]} -- matrix on the left multiplies each
element on the right.
The standard kronecker() function is the right Kronecker product,
A \otimes_R B = {A[i,j] * B} -- matrix on the right multiplies each
element on the left.
The example below shows the result of
2007 Jul 31
5
extract columns of a matrix/data frame
Hello all,
I have a matrix whose column names look like
a1 a2 b1 b2 b3 c1 c2
1 2 3 7 1 3 2
4 6 7 8 1 4 3
Now, I can have any number of a's. not just two as shown above and same goes for b's and c's. I need to extract all the a's columns and put them in another matrix, extract all b's columns and put them in some matrix
2005 Aug 15
2
queer data set
I have a dataset that is basically structureless. Its dimension varies
from row to row and sep(s) are a mixture of tab and semi colon (;) and
example is
HEADER1 HEADER2 HEADER3 HEADER3
A1 B1 C1 X11;X12;X13
A2 B2 C2 X21;X22;X23;X24;X25
A3 B3 C3
A4 B4 C4 X41;X42;X43
A5 B5 C5 X51
etc., say. Note that a blank
2013 Mar 13
5
string split at xth position
Hi,
I have a vector of strings like:
c("a1b1","a2b2","a1b2") which I want to spilt into two parts like:
c("a1","a2","a2") and c("b1","b2,"b2"). So there is
always a first part with a+number and a second part with b+number.
Unfortunately there is no separator I could use to directly split
the vectors.. Any idea
2010 Jul 17
4
sort file names in numerical order
Hello,
I get some file names by list.files().
These names are in alphabetical order.
I want to change it to logical numeric order.
Example:
> fileNames <- c("A10", "A1", "A2", "B1", "B2", "B10")
> sort(fileNames)
[1] "A1" "A10" "A2" "B1" "B10" "B2"
I want to have:
2009 Oct 29
3
Removing & generating data by category
Dear R users,
Basically, from the following arbitrary data set:
a <-
data.frame(id=c(c("A1","A2","A3","A4","A5"),c("A3","A2","A3","A4","A5")),loc=c("B1","B2","B3","B4","B5"),clm=c(rep(("General"),6),rep("Life",4)))
> a
2007 Nov 13
7
combine two dataframe
I have two data frame A and B adn want to cross them.
A has format as:
a1 a2 a3
1 2 3
2 3 1
1 3 2
...
B:
b1 b2
1 2
2 1
...
the combine result shall be something like
a1 a2 a3 b1 b2
1 2 3 1 2
1 2 3 2 1
2 3 1 1 2
2 3 1 2 1
1 3 2 1 2
1 3 2 2 1
....
is there a function able of doing this instead of loops?
Thanks,
Sun
2009 Nov 29
1
Plotting observed vs. fitted values
Dear Wiza[R]ds,
I am very grateful to Duncan Murdoch for his assistance with this problem.
His help was invaluable. However, the problem has become a little more
complicated for me. Now, in each plot, I need to plot the observed and
fitted values of a supine and upright posture experiment. Here is what I
have and how far I got.
# tritiated (3H)-Norepinephrine(NE) disappearance from plasma
#
2009 Mar 20
4
how to make aggregation in R ?
Hi,
I am trying to aggregate the sum of my test data.frame as follow:
testDF <- data.frame(v1 = c("a", "a", "a", "a", "a", "b", "b", "b", "b",
"b", "c", "c", "c", "c", "c", "d", "d", "d", "d",
2012 Oct 18
7
summation coding
I would like to code the following in R: a1(b1+b2+b3) + a2(b1+b3+b4) +
a3(b1+b2+b4) + a4(b1+b2+b3)
or in summation notation: sum_{i=1, j\neq i}^{4} a_i * b_i
I realise this is the same as: sum_{i=1, j=1}^{4} a_i * b_i - sum_{i=j} a_i
* b_i
would appreciate some help.
Thank you.
--
View this message in context: http://r.789695.n4.nabble.com/summation-coding-tp4646678.html
Sent from the R
2011 Jan 04
1
Cost-benefit/value for money analysis
I assume this has a "proper" name, but I don't know what it is and wondered
if anyone knew of a package that might do the following, or something
similar.
As an example, assume I have borrowed and read 10 books on R , and I have
subjectively given each of them a "value" score in terms of how useful I
think they are. I also know how much each costs in terms of money.
What
2003 Oct 04
2
mixed effects with nlme
Dear R users:
I have some difficulties analizing data with mixed effects NLME and the
last version of R. More concretely, I have a repeated measures design with
a single group and 2 experimental factors (say A and B) and my interest is
to compare additive and nonadditive models.
suj rv A B
1 s1 4 a1 b1
2 s1 5 a1 b2
3 s1 7 a1 b3
4 s1 1 a2