similar to: How to apply a function on each column of a matrix

Displaying 20 results from an estimated 20000 matches similar to: "How to apply a function on each column of a matrix"

2010 Jan 29
3
Applying a function on each columns of a matrix
Hello everyone, I have the following matrix [,1] [,2] [,3] [,4] [1,] 0.002809706 0.0063856960 0.0063856960 0.011749681 [2,] 0.004893124 0.0023118418 -0.0005122951 -0.014646465 [3,] 0.003547897 0.0063355297 0.0030410542 0.011403953 [4,] 0.004838299 -0.0040383645 -0.0090406831 -0.011027569 [5,] 0.035648755 0.0334815590 0.0380977404
2008 May 09
1
Rescaling a column in a matrix based on a certain rows
Hi, Let say I have this matrix: > mat<-matrix(cbind(rnorm(20),rnorm(20)), ncol = 2) And I want to rescale values of column [,1] and [,2] using values from row 1 to 5, such that the values of row 1:5 should be rescale to the same amplitude (kinda like take the z-score of population from row 1:5). column 1 and 2 are two different samples need to be compared. I hope I made myself clear
2007 Jan 17
2
Repeated measures
I am having a hard time understanding how to perform a "repeated measures" type of ANOVA with R. When reading the document found here: http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_repms.html I find that there is a reference to a function make.rm () that is supposed to rearrange a "one row per person" type of frame to a "one row per observation" type
2011 Mar 08
1
repeat matrix column within each array third dimension
Hello all, I'm working with a matrix that will have varying dimensions. It will populate an array such that the number of matrix columns will determine the number of 3rd dimension levels of the array. Rows will be the same for both. For this example lets say the array will have 2 columns, but that's not fixed. dim(arr)<-c(dim(mat)[1],2,dim(mat)[2]) I wish to repeat each matrix
2002 Oct 29
2
Apply function to column of array
Hi all, I would like to apply a function to each column of an 2-dimensional array, and store the result in a new 1-dimensional vector. I am not sure how to go about doing that syntatically. For instance, can I use lapply? And, if so, how do I specify which dimension should be used? Also, how do I pre-specify the type of object that will go into the 1-dimensional vector. I'm not sure if
2011 Jan 11
1
how to coerce part of each column of a matrix to a vector and merge them
Hello Suppose I have a matrix mat=(1:16,2) [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 there is a vector end=c(2,3,1,3) #coerce the 1st 2 numbers of the 1st column to a vector [1] 1 2 #coerce the 1st 3 numbers of the 2nd column and append it to the previous vector [1] 1 2 5 6 7 #coerce the 1st number of
2012 Oct 23
1
Testing proportional odds assumption in R
I want to test whether the proportional odds assumption for an ordered regression is met. The UCLA website points out that there is no mathematical way to test the proportional odds assumption (http://www.ats.ucla.edu/stat//R/dae/ologit.htm), and use graphical inspection ("We were unable to locate a facility in R to perform any of the tests commonly used to test the parallel slopes
2010 Dec 02
1
Arrange elements on a matrix according to rowSums + short 'apply' Q
Greetings, My goal is to create a Markov transition matrix (probability of moving from one state to another) with the 'highest traffic' portion of the matrix occupying the top-left section. Consider the following sample: inputData <- c( c(5, 3, 1, 6, 7), c(9, 7, 3, 10, 11), c(1, 2, 3, 4, 5), c(2, 4, 6, 8, 10), c(9, 5, 2, 1, 1) ) MAT <- matrix(inputData,
2011 Jan 11
1
how to use "apply" function partial to each vector of a matrix
Hello Suppose I have a matrix mat=(1:16,2) [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 I just want to use the "apply" function to the matrix partially there is a vector end=c(2,3,1,3) #sum the 1st 2 numbers of the 1st column #sum the 1st 3 numbers of the 2nd column #sum the 1st number of the 3rd column
2010 Feb 02
1
Build a matrix from another matrix by specifying the indexes
Hello R specialists, I have a base vector called vBase with 102 elements. I have another vector vec1 which elements are only part of vBase but is shorter. I transform vec1 so I get a vector with the same size as vBase and with each common element on the same indexed row. If a value is missing in vec1 then I put a Na like this: vec1 vBase Amsterdam Amsterdam Na
2010 Oct 10
2
How to add a new column to a matrix?
Hi - I am a beginner to the R language. I have written the following matrix: Z.mat=matrix(c(2,2,2,1,1,1,3,2,1,6,5,4,9,1,1,2,3,2), nrow=6) I would like to add a 4th column consisting of: 6, 9, 8, 15, 16, 17 I would also like to name each column a, b, c, d as well. Thanks! [[alternative HTML version deleted]]
2008 Jan 15
1
Newbie Question -- Remove entire column in a matrix
I'm ordering "The R Book" and hope to learn a lot more about R. In a meantime, I have a matrix of digits and I would like to look for a column that contains zeroes and remove the entire column from the matrix. I can write a piece of R code to do that (and it works); however, I think the R-experts have more tricks to do such a 'simple' thing. Many thanks in advance.
2010 Jul 11
2
simple apply syntax
I know this is a simple question, but I have yet to master the apply statements. Any help would be appreciated. I have a column of probabilities and sample sizes, I would like to create a column of binomial random variables using those corresponding probabilities. Eg. mat = as.matrix(cbind(p=runif(10,0,1), n=rep(1:5))) p n [1,] 0.5093493 1 [2,] 0.4947375 2 [3,]
2008 Oct 05
3
efficient use of lm over a matrix vs. using apply over rows
I have a large matrix, each row of which needs lm applied. I am certain than I read an article in R-news about this within the last year or two that discussed the application of lm to matrices but I'll be darned if I can find it with Google. Probably using the wrong search terms. Can someone steer me to this article of just tell me if this is possible and, if so, how to do it? My simplistic
2007 Mar 12
1
How to modify a column of a matrix
? stato filtrato un testo allegato il cui set di caratteri non era indicato... Nome: non disponibile Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070312/5b30b712/attachment.pl
2010 Jun 10
2
adding column of ordered numbers to matrix
Hello everyone, I have a matrix of over 40000 line and about 30 columns. For my analysis I would like to add another column with ascending numbers (column header should be "order", and than 1,2,3,4 ....the end of the matrix). During my analysis I reorder them ( due to merge commands by a different column). How do I add such a column in an ascending order (or descending for what it
2009 Jul 24
1
How to convert a matrix to a dataframe and makes its first row be the column name
Hi I want to convert a matrix to a dataframe. The matrix is like this Site A B C D X 1 2 3 4 Y 5 6 7 8 Z 9 10 11 12 The converted dataframe need to have the first row as column names and the values of each column (1, 2, 3, 4; ......12;) be numeric, not factors. I used data.frame(), but it gave me auto-assigned column
2007 May 01
2
Matrix column name
Dear R users, Having searched the mail archive I think the conclusion was that it is not possible to have a column name when there is only one column in the matrix. But I thought I'd check with the more experienced users. What I tried to do was: in a loop I pick a column, record the column name and remove the column from the matrix. But when there were 2 columns left, after one column was
2007 Jun 06
1
error message: only first element in each line of matrix used
I have a matrix and am trying to write a code to 1. identify all neg values along each line 2. for each neg value I need to identify min(j+3) 3. end with this code: eq[i,j]<- ifelse(mat.r[i,j] < (0.5*mat.s[i,j]), mat.all[i,j], 0) This is the code I have so far. I have tried several different methods but I keep getting the same error message that the condition has length >1 and only
2012 Oct 05
3
loop for column substraction of a matrix
Dear useRs, I have a matrix with 38 columns and 365 rows. what i want to do is the following..... 1. subtracting from each column, first itself and then all the remaining columns. More precisely, from column number 1, i will first subtract itself(column 1) and then the remaining 37 columns. Afterwards i will take column number 2 and do the same. In this way i want to proceed till 38th column.