Displaying 20 results from an estimated 20000 matches similar to: "Help: convert entry of a list into a matrix"
2011 Aug 24
2
Help: find the index of the minimum of entries
Dear All,
I would like to ask a question on how to find the index of the minimum of entries of a numeric vector, without using loops or user defined functions.
Suppose we have a vector:
a <- c(3,1,2)
then,
min(a) = 1
and its index is 2.
Target: how to get the index of this minimum? How to get the indices if multiple entries assume this same minimum?
Thank you,
Chee
[[alternative HTML
2012 Jan 24
2
Help: read a proportion of high through-put data
Dear All,
I have a text file, tab delimited, called "sample.txt",as follows:
ID_REF 382 GC_Score Theta R B_Allele_Freq Log_R_Ratio
200003 BB 0.9101527 0.9734979 0.8788951 1 0
200006 AB 0.6003323 0.4385073 2.033364 0.4850979 0.01553433
I have explored various options of the command: read.table, with one as:
2011 Aug 04
1
matrix rows to single numeric element
I have a matrix of 5 columns and 64 rows, let's call it "mat1". All values are 1 or 0. I need to take the values of the elements by row and create a single numeric element that can be placed its respective slot in a 64-element list, named "list1". For example, mat1[11,1:5] = 0,1,1,0,1 and I must put 01101, with a length of 1, into the 11th element of list1. I can create
2010 Mar 02
2
turn character string into unevaluated R object
Hi,
How to turn a character string into an unevaluated R object? I want to load some files in a directory into data matrix R objects. I could do this with read.table and assign (see below). Then, I want to turn the character string representing a file name (the evaluated expression of i) into an unevaluated R object. Basically, I want to create matrices whose names are the same as the related file
2011 Aug 24
1
Help: extrac the first entry for each component of a list
Dear All,
I would like to know, beside writing a function and then apply it to a list, or using a for loop, whether there is a one-line command to do the following.
Suppose we have a list, each of whose components are numeric:
> a <- vector("list",3)
> a[[1]] <-c(1,2)
> a[[2]] <-c(3,4)
> a[[3]] <- c(5,6)
> a
[[1]]
[1] 1 2
[[2]]
[1] 3 4
[[3]]
[1] 5 6
Target:
2011 Apr 15
1
How to generate a correlation matrix with restrictions on its eigenvalues
Dear All,
I would like to generate m positive real numbers c_i, I=1,...,m, such that
(1) c_1 + c_2 + ... + c_m=m,
(1) after being ordered into c_1 >= c_2 >= .... >=c_m>0, we have that c_m is of the same order of m^(-1/8), when m is sufficiently large.
Thanks,
-Chee
[[alternative HTML version deleted]]
2007 Nov 12
1
update matrix with subset of it where only row names match
I guess this has a simple solution:
I have matrix 'mat1' which has row and column names, e.g.:
A B C
row1 0 0 0
row2 0 0 0
....
rown 0 0 0
I have a another matrix 'mat2', essentially a subset of 'mat1' where the
rownames are all in 'mat1' e.g.:
B
row3 5
row8 6
row54 7
I want to insert the values of matrix mat2 for column B (in reality it
could be some or
2013 Sep 26
1
Grouping Matrix by Columns; OHLC Data
HI,
May be this helps:
set.seed(24)
?mat1<- matrix(sample(1:60,30*24,replace=TRUE),ncol=24)
colnames(mat1)<- rep(c("O","H","L","C"),6)
indx<-seq_along(colnames(mat1))
n<- length(unique(colnames(mat1)))
?res<- lapply(split(indx,(indx-1)%%n+1),function(i) mat1[,i])
lapply(res,head,2)
#$`1`
#????? O? O? O? O? O? O
#[1,] 18 56 51 24 24 52
#[2,]
2010 Jan 29
7
Simple question on replace a matrix row
Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I want to
replace the first row of mat2 with mat1, this is what I do:
mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand, I want
it to stay a matrix...
-----
Anna Lippel
--
View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-tp1427857p1427857.html
Sent from the R help
2012 Nov 16
4
Multiple Vector with matrix in R
Hi
Can someone show me an easy way to multiple a weighted vector with an
matrix?
example below
mat1<-matrix(sample(1:100,80,replace=TRUE),ncol=8)
w <- 1/1:10
I want the first element in w to be multiplied by the first row of mat1 and
2nd element in w to be multiplied with the 2nd row and so on.
I have huge matrix is there an easy way other than diag(w)%*%mat1
Thanks
--
View this
2007 Nov 21
2
matrix elementwise average with NA's
Hello fellow R users,
I have a matrix computation that I imagine should be relatively easy to do, however I cannot figure out a nice way to do it. I have two matrices, for example
mat1 <- matrix(c(1:5,rep(NA,5), 6:10), nrow=3, byrow=T)
mat2 <- matrix(c(2:6, 6:10, rep(NA,5)), nrow=3, byrow=T)
I'd like to compute the element-wise average for non-NA entries. Of course
(mat1+mat2)/2
2010 Mar 29
2
Need help on matrix manipulation
Dear all,
Ket say I have 3 matrices :
mat1 <- matrix(rnorm(16), 4)
mat2 <- matrix(rnorm(16), 4)
mat3 <- matrix(rnorm(16), 4)
Now I want to merge those three matrices to a single one with dimension
4*3=12 and 4 wherein
on resulting matrix, row 1,4,7,10 will be row-1,2,3,4 of "mat1", row
2,5,8,11 will be row-1,2,3,4 of "mat2" and row 3,6,8,12 will be row-1,2,3,4
of
2003 Mar 20
2
Matrix problems
Hi all.
I do not know if it is a bug in the windows version but i have this
problem.
Reading a file with 200000 rows, 2 columns and transforming into a
200000 x 2 matrix.
If I try to find an element by using the which command which gives
some correct indexes plus some others passing the 200000 row
boundaries.
If I try to reach those "outbound" indexs I get an "Error: subscript out
2011 Apr 29
3
How to define specially nested functions
Dear All,
I would like to define a function: f(x,y,z) with three arguments x,y,z, such that: given values for x,y, f(x,y,z) is still a function of z and that I am still allowed to find the root in terms of z when x,y are given.
For example: f(x,y,z) = x+y + (x^2-z), given x=1,y=3, f(1,3,z)= 1+3+1-z is a function of z, and then I can use R to find the root z=5.
Thank you.
-Chee
[[alternative
2013 Jan 04
2
Working with Matrix
Hello again,
Let say I have 2 matrices which equal number of columns but different
number of rows like:
Mat1 <- matrix(1:20, 4, 5)
Mat2 <- matrix(1:25, 5, 5)
Now for each column 1-to-5 I need to fetch the corresponding columns
of these 2 matrices and add the corresponding elements (ignoring NA
values if any). Therefore for the 1st column I need to do:
(1+1), (2+2),...,(4+4), (NA+5)
and
2011 May 01
2
Question on where samples are grouped in rmvnorm{mvtnorm}
Dear All,
For function: rmvnorm{mvtnorm} in (library mvtnorm, not splus2R), if I generate 2 bivariate normal samples as follows:
> rmvnorm(2,mean=rep(0,2),sigma=diag(2))
[,1] [,2]
[1,] 2.0749459 1.4932752
[2,] -0.9886333 0.3832266
Where is the first sample, it is stored in the first row or the first column?
Does this function store samples row-wise or column-wise?
Thank
2011 Aug 23
1
Help: Sort components of a vector with indices tracked in R
Dear All,
I would like to know how to sort a vector of numeric values such that we know the original index of each ordered component. Say, we have
c <- c(1,4,3,2)
csort <- sort(c,descreasing=FALSE)
With a few components of c, we can manually find out:
csort[1] = 1 = c[1], ie, the original index of csort[1] is 1,
csort[2] =2 =c[4], ie, the original index of csort[2] is 4.
When length(c) is
2012 Mar 10
1
Help on subgraphs in xyplot of lattice library
Dear All,
I would like to ask a question on how to do overlay plots in each subgraph of xyplot.
1. I did simulations for m=1000, 2500, 5000, 10000, as the sample sizes.
2. for each sample size value m, 4 graphs are generated; each graph contains overlayed comparisons between 4 methods,
3. now I want put them into a 4-by-4 plot by xyplot, i.e., 4 sample size values, each of which has 4 plots.
2010 Feb 12
3
Code working but too slow, any idea for how to speed it up ?(no loop in it)
Hello my friends,
here is a code I wrote with no loops on matrix that is taking too long (2
seconds and I call him 720 times --> 12 minutes):
mat1 and mat2 are both matrix with 103 columns and 164 rows.
sequence <- matrix(seq(1 : ncol(mat1)))
returns <- apply(sequence, 1, function, mat1= mat1, mat2 = mat2, day = 1)
function<- function(mat1, mat2, colNb, day){
2010 Jan 27
1
How to sort data.frame
Dear R heleprs
Suppose I have following data
Scenarios
combination_names
series1
series2
Sc1
MAT2 GAU1
7.26554
8.409778
Sc2
MAT2 GAU2
7.438128
8.130275
Sc3
MAT3 GAU1
8.058422
8.06457
Sc4
MAT1 GAU2
8.179855
8.022071
Sc5
MAT3 GAU2
8.184033
8.191831
Sc6
MAT3 GAU2
7.50312
8.232425
Sc7
MAT1 GAU2
7.603291
8.200993
Sc8
MAT1 GAU1
8.221755
8.380097
Sc9
MAT3 GAU2
7.904908