Displaying 20 results from an estimated 10000 matches similar to: "Simply matrix slice question"
2009 Mar 25
3
Converting a Matrix to a Vector
Say I have:
> set.seed( 1 )
> m <- matrix( runif(5^2), nrow=5, dimnames = list( c("A","B","C","D","E"),
> c("O","P","Q","R","S") ) )
> m
O P Q R S
A 0.2655087 0.89838968 0.2059746 0.4976992 0.9347052
B 0.3721239 0.94467527 0.1765568
2011 Mar 04
2
sum of digits or how to slice a number into its digits
Dear R colleagues,
I face a seemingly simple problem I couldn't find a solution for myself
so far:
I have to sum the digits of numbers. Example: 1010 ->2 100100110 -> 4
Unfortunately there seems not to be a function for this task. So my idea
was to use sum(x) for it. But I did not figure out how to slice a number
to a vector of its digits. Example (continued from above): 1010 ->
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,
2008 Oct 24
2
how to simply the procedure of creating a group of data.frame?
Dear R users,
I want to creat a group of data frames, such as:
d1<-data.frame(x=factor(),y=numeric(),...)
d2<-data.frame(x=factor(),y=numeric(),...)
d3<-data.frame(x=factor(),y=numeric(),...)
:
:
d50<-data.frame(x=factor(),y=numeric())
How can I use the loop to simply my procedure?
Thanks advance
Ted
--
View this message in context:
2011 May 17
2
Minimum value by ID
Hello,
I have a longitudinal dataset where each individual has a different number
of entries. Thus, it is of the following structure:
x <- runif(12)
id.var <- factor(c(rep("D1",4),rep("D2",2),rep("D3",3),rep("D4",3)))
dat <- as.data.frame(x)
dat$id.var <- id.var
dat
> dat
x id.var
1 0.9611269 D1
2 0.6738606 D1
3
2009 Mar 06
2
How to apply a function to slices of multidimensional arrays, and not just iterating through single elements
Hello,
If I want to apply some f(x) to such chunks of the the array
dim(A)==c(d1,d2,d3,..,dk,...,dn) which are defined by A[...,ik,...]
(ik belongs to {1,..,dk}), for now I use iteration via 'for (i in
dim(A)[k]) f(A[...,k,...])' . Is there any more elegant approach, e.g
like in 'apply' function which you can use on margin of the array.
Just in my case I want the entire slice
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,
2012 Apr 20
3
Matrix multiplication by multple constants
Dear R helpers
Suppose
x <- c(1:3)
y <- matrix(1:12, ncol = 3, nrow = 4)
> y
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12
I wish to multiply 1st column of y by first element of x i.e. 1, 2nd column of y by 2nd element of x i.e. 2 an so on. Thus the resultant matrix should be like
> z
[,1] [,2] [,3]
[1,] 1
2003 Nov 08
5
accessing windows clipboard from load and save (PR#4999)
Full_Name: Gabor Grothendieck
Version: 1.7.1
OS: Windows 2000
Submission from: (NULL) (207.35.143.81)
save(x,ascii=TRUE,file("clipboard"))
works but
load(file("clipboard"))
does not.
Even better would be if
save(x,ascii=TRUE,"clipboard")
and
load("clipboard")
worked as that would provide consistency with
2009 Feb 17
2
Efficient matrix computations
Hi,
I am looking for two ways to speed up my computations:
1. Is there a function that efficiently computes the 'sandwich product' of
three matrices, say, ZPZ'
2. Is there a function that efficiently computes the determinant of a
positive definite symmetric matrix?
Thanks,
S.A.
[[alternative HTML version deleted]]
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,
2010 Jul 26
2
Concatenate a mix of numbers and letters to create a vector name
Dear all,
I am trying to create a vector name, for example tmax.195012 from tmax., 1950 and 12. Obviously I don't wish to simply type it because the 3 name components are changing in each iteration within a loop. Is there any way of concatenating those 3 components (which are a mixture of numbers and letters)?
Thanks for reading,
Panos
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
2007 Apr 12
1
Assignment from list
I have a list of groups of xy positions I want to set to 0 in an
array full of 1s. When the assignments are done directly from the
list, they are incorrect, while if I use a temporary array derived
from the list the assignments are correct. The following example will
hopefully make my problem clearer.
The matrices z and zz are initialised with 1. The z and zz values at
coordinates in
2010 Mar 09
3
Removing Zeros from matrix
Hi Everybody,
I have a matrix of about 45 columns. Some of the rows contain zeros. Using
>data1<-data[complete.cases(data),], I can remove the "NA" rows. But I am
unable to tackle that of zeros.
Can anybody give me an idea of how to remove rows containing zeros in a
matrix.
Thanks so much
Best
Ogbos
[[alternative HTML version deleted]]
2008 Oct 14
4
request: How to ignore columns having zero sums
Dear friends
I have an array consist of r-rows and c-columns e.g.
x=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0);
x1=array(x, dim=c(4,6))
output is
> x1
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 2 3 4 0 0
[2,] 1 2 3 4 0 0
[3,] 1 2 3 4 0 0
[4,] 1 2 3 4 0 0
How can i ignore columns having zero sums? Help in this regard
2010 Sep 06
3
Aggregate certain rows in a matrix
Hi,
I have a matrix that looks like this
a <- c(1,1,1,1,2,2,3,3,3,3)
b <- c(2,2,2,3,4,4,4,5,5,6)
c <- c(1,2,3,4,5,6,7,8,9,10)
M <- matrix(nr=10,nc=3)
M[,1] <- a
M[,2] <- b
M[,3] <- c
> M
[,1] [,2] [,3]
[1,] 1 2 1
[2,] 1 2 2
[3,] 1 2 3
[4,] 1 3 4
[5,] 2 4 5
[6,] 2 4 6
[7,] 3 4 7
2009 Jun 08
5
mean
Hi,
I have gote the following data
x1 <- c(rep(1,6),rep(4,7),rep(6,10))
x2 <- rnorm(length(x1),6,1)
data <- data.frame(x1,x2)
and I would like to compute the mean of the x2 for each individual of x1, i. e. x1=1,4 and 6?
Thank you very much in advance,
Amori
[[alternative HTML version deleted]]
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