Displaying 20 results from an estimated 10000 matches similar to: "Matrix multiplication by multple constants"
2011 Aug 23
4
Correlation discrepancy
Dear R list, I have one very elementary question regrading correlation between two variables.
x = c(44,46,46,47,45,43,45,44)
y = c(44,43,41,41,46,48,44,43)
> cov(x, y)
[1] -2.428571
However, if I try to calculate the covariance using the formula as
covariance = sum((x-mean(x))*(y-mean(y)))/8 # no of of paired obs. = 8
or
covariance = sum(x*y)/8-(mean(x)*mean(y))
gives
2010 Nov 09
3
Row-wise recurive function call
Dear Group,
I have a following dataset:
> a
A B C D
1 22 3 31 40
2 26 31 36 32
3 3 7 49 16
4 24 40 27 26
5 20 45 47 0
6 34 43 11 18
7 48 48 24 2
8 3 16 39 48
9 20 49 7 21
10 17 36 47 10
> dput(a)
structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L,
17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L),
C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L,
2010 Nov 07
3
regular exprs
Dear All,
I would appreciate any help with the following: given the vector 'x'
x <- c("Ass1", "Ass.s1", "Ass2", "Ass.s2")
I would like to pick up the positions where the character string
contains "Ass" but does not contain "Ass.s", so for 'x' that would be
positions 1 and 3.
I guess this could be programmed around
2012 Nov 01
3
convert list without same component length to matrix
Hi,
I have this lame question. I want to convert a list (each with varies in
length) to matrix with same row length by eliminating vectors outside the
needed range.
For example:
l<-list(NULL)
l[[1]]=1,2,3.7
l[[2]]=3,4,5,6,3
l[[3]]=4,2,5,7
l[[4]]=2,4,6,3,2
l[[5]]=3,5,7,2
#so say I want to only have 4 rows and 5 column in my matrix (or
data.frame) and eliminating the 5th index value in l[[2]]
2010 Oct 15
4
split data with missing data condition
Dear all
I have data like this:
x y
[1,] 59.74889 3.1317081
[2,] 38.77629 1.7102589
[3,] NA 2.2312962
[4,] 32.35268 1.3889621
[5,] 74.01394 1.5361227
[6,] 34.82584 1.1665412
[7,] 42.72262 2.7870875
[8,] 70.54999 3.3917257
[9,] 59.37573 2.6763249
[10,] 68.87422 1.9697770
[11,] 19.00898 2.0584415
[12,] 60.27915 2.5365194
[13,] 50.76850
2012 Feb 20
2
Column wise matrix multiplication
Hi all,
I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.) function in Matlab does, i.e.
A <-matrix(c(1:10),5,2)
V = A[,1]*A[,2]
Thank you
Graziano
[[alternative HTML version deleted]]
2011 Aug 24
1
Passing a large amount of parameters to a function
Hello,
I have a function with a long list of parameters (of different types,
numeric and string)
myFunc <-function(p1, p2, p3, p4, p5...etc)
{
do.something(p1,p2,....)
}
I want to loop over this to provide a different set of parameters to the
list every time.
for (ii in 1:N)
{
myFunc(p1(ii), p2(ii),....etc)
}
I would like to simplify the notation and use some kind of structure, maybe
2008 Sep 17
5
Loop on vector name
[My previous message rejected, therefore I am sending same one with some modification]
I have 3 vectors with object name : dat1, dat2, dat3
Now I want to create a loop, like :
for (i in 1:3)
{
cat(sd(dati))
}
How I can do this in R?
Regards,
2012 Feb 12
3
Vector manipulation
Hello,
I am stuck with the following problem. Consider the vector:
vec <- c(2,4,6,9,10)
I now want to use R to manipulate the vector as follows:
[1] 2, 4, 2, 6, 2, 9, 2, 10
In words, the first element of the vector should be placed in front of each
following number.
Which R commands do I need to achieve that?
Cheers
--
View this message in context:
2010 Oct 21
1
How to check for missing report pages per client
Hi,
Not sure how to go about checking for missing report pages per client. See
example below; I like to extract client 730040, because page 46103 is missing.
client page
730001 46101
730001 46102
730019 46101
730035 46101
730040 46101
730040 46102
730040 46104
730040 46105
730052 46101
730052 46102
730074 46101
730074 46102
730074 46103
I appreciate any help,
Pauline
2010 Nov 17
2
slicing list with matrices
A list contains several matrices. Over all matrices (list elements) I'd like to access one matrix cell:
m <- matrix(1:9, nrow=3, dimnames=list(LETTERS[1:3], letters[1:3]))
l <- list(m1=m, m2=m*2, m3=m*3)
l[[3]] # works
l[[3]][1:2, ] # works
l[[1:3]][1, 1] # does not work
How can I slice all C-c combinations in the list?
S?ren
--
S?ren Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag,
2010 Nov 25
1
Applying function to elements of matrices in a list
Hello R-help,
Please cc me on all responses, as I only receive summary emails from
this list.
I'm wondering if anybody has any tips on how to accomplish this
efficiently. I have a list of matrices, and I'm trying to get the mean
of the [i,j]'th element of each matrix in a list.
So if I have a list of matrices, say
x <-
2011 Feb 16
2
Axis positions
Hi everyone.
I would like to modify the axis on my plot.
First, I would like to make a plot without the box. so I use :
plot(x,y, axes = FALSE, type = 'l')
Then, I call :
axis(1, tck = -0.02)
axis(2, tck = -0.02)
to have X and Y axis appear. However, I would like them to join at the
origin instead of having a space between the 2 axis. I can't find the
parameter to modify to get
2011 Jun 14
1
Expand DF with all levels of a variable
Dear list,
I would like to expand a DF with all the missing levels of a variable.
a <- c(2,2,3,4,5,6,7,8,9)
a.cut <- cut(a, breaks=c(0,2,6,9,12), right=FALSE )
(x <- data.frame(a, a.cut))
# In 'x' the level "[0,2)" is "missing".
AddMissingLevel <- function(xdf) {
xfac <- factor( c("[0,2)", "[2,6)", "[6,9)",
2011 Jun 24
1
Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Hi All,
What is the fastest way of finding if any members of vector x fall in the
range of the rows of matrix y?
I do not want to use two for loops as this will take forever.
Any help will be appreciated,
best,
salih
[[alternative HTML version deleted]]
2011 Aug 25
1
Bivariate normal regression in R
Hello everyone,
I need to fit a bivariate normal regression model to a dataset where the
same covariate (say, X) influences two separate but correlated responses
(say, Y1 and Y2). So, the bivariate
model would look like :
Y1 = a1 + b1*X + e1
Y2 = a2 + b2*X + e2
where e1 and e2 are error terms which can be correlated. Is there any
package in R which can help me fit this model ? Any help will be
2011 Aug 31
1
assign group letters to T/F matrix
dear R community,
i appologize as this is kind of a newbie question, but:
I want to assign group letters (like in anova post-hoc tests) to data
with combined means and SDs. It's easy to apply t-test formulas to get
a materix like
(A - D are treatments
| A B C D
-----------------------
A| T F F
B| T F
C| F
D|
where true stands for sign.
2011 Sep 04
2
Regression coefficient constraints
Hi Guys,
Does anyone know how I could constrain my regression coefficients so that they are positive and add up to one? Any help will be greatly appreciated.
Kind Regards,
Andre
[[alternative HTML version deleted]]
2011 Sep 19
2
pasting elements of one character vector together
hello,
i am familiar with the paste command with which i can paste for exaple:
object <- "Hello"
paste(object,"World")
now i would like to be able to paste all the elements of the same vector
together e.g:
object <- c("Hello","World")
getting as a result also:
"Hello World".
Does anyone know the solution to this problem?
Thank you
2011 Sep 29
1
multiplying list with vector
hello everybody,
i have got a question about lists:
i have got the following commands:
mylist <- list("v1"=c(1,2,2,1),"v2"=c(2,2,2,1),"v3"=c(1,1,1,1))
myvector <- c(100,10000,1000000)
now i would like to multiply each element of the list with the corresponding
element of the vector, that is to say:
v1*100
v2*10000
v3*1000000
i only could think of lapply