similar to: comparing matrices

Displaying 20 results from an estimated 20000 matches similar to: "comparing matrices"

2013 Jan 02
2
In which column and in which row a number is in a matrix
Dear all, Happy New Year for all of you! I hope we have an year of essential freedom for everyone! I am trying to manipulate a matrix in order to know in which column and in which row a number is allocated. But, when we use the function "which" it returns the position of the number in the "vector representation of the matrix". For example: >
2006 Mar 15
7
matrix indexing
Can someone please give me a pointer here. I have two matrices matA A B C 1 5 2 4 2 2 4 3 3 1 2 4 matB A B C 1 TRUE FALSE TRUE 2 FALSE TRUE TRUE 3 FALSE FALSE FALSE how do I extract all the values from matA where the coresponding entry in matB == TRUE (or FALSE), perferably in vector form. Many thanks tom
2009 Apr 27
3
Formatting numbers
I've been trough the R documentation for about half an hour and it's not clear to me how to do this: I need to format to character a series of integers from 1 to 1000, and I like them to look like "0001" "0002", "0059", "0123" and so on. Padded with zeroes to have four digits. Cheers! Mario. r-help-request at r-project.org wrote: > Send
2012 Dec 02
1
overlapping graphs in logarithmic y-axis
dear useRs, i want to overlap graphs of two matrices in such a way that the y-axis of graph should be "logarithmic" against normal x-axis. i am, unsuccessfully, trying the followings >matplot(mata, log="mata",type = "l", col="red)>lines(mata, log="matb",type = "l", col="yellow") could you please help me out on it?? thanks in
2012 Nov 05
2
averaging a list of matrices element wise
Dear all, I have a list of n matrices which all have the same dimension (r x s). What would be a fast/elegant way to calculate the element wise average? So result[1, 1] <- mean(c(raw[[1]][1, 1] , raw[[2]][1, 1], raw[[...]][1, 1], raw[[n]][1, 1])) Here is my attempt. #create a dummy dataset n <- 3 r <- 5 s <- 6 raw <- lapply(seq_len(n), function(i){ matrix(rnorm(r * s), ncol =
2009 Jun 20
1
how to apply the dummy coding rule in a dataframe with complete factor levels to another dataframe with incomplete factor levels?
Dear R helpers: Sorry to bother for a basic question about model.matrix. Basically, I want to apply the dummy coding rule in a dataframe with complete factor levels to another dataframe with incomplete factor levels. I used model.matrix, but could not get what I want. The following is an example. #Suppose I have two dataframe A and B
2009 Jan 13
5
indexing question
Hi all, i have a pretty easy indexing question, at least i believe so. The main reason i post it here, is that brackets and $ are hard to google. How do I index correctly, if i just want to display the whole dataset conditioned on the fact that some particular column equals one. I know i can do something like: data$somecolumn[data$particularcol ==1] . That will show all "some
2010 Apr 14
5
Running cumulative sums in matrices
Dear R-helpers, I have a huge data-set so need to avoid for loops as much as possible. Can someone think how I can compute the result in the following example (that uses a for-loop) using some version of apply instead (or any other similarly super-efficient function)? example: #Suppose a matrix: m1=cbind(1:5,1:5,1:5) #The aim is to create a new matrix with every column containing the
2009 Apr 10
3
turning list into vector/dataframe
Hi, I have used this command : resamples<-lapply(1:1000,function(i) sample(lambs,replace=F)) resamples2<-lapply(resamples,Cusum) to get a list of 1000 samples of my data. The function Cumsum is defined as follows: Cusum<-function(x){ SUM<-cumsum(x)-(1:length(x))*mean(x) min<-min(cumsum(x)-(1:length(x))*mean(x)) max<-max(cumsum(x)-(1:length(x))*mean(x)) diff<-max-min
2013 Apr 24
2
Distance matrices Combinations
Dear UseRs, MY PROBLEM IS A SMALL PIECE OF A REAL BIG AND A COMPLICATED PROBLEM. IF I DELIBERATE IN A VERY SIMPLE WAY THEN ALL I WANT IS TO PUT ALL THE POSSIBLE COMBINATIONS OF 75 DISTANCE MATRICES (BY TAKING 4 MATRICES, MORE COMMONLY 75C4), in the following equation. t<-as.matrix((MAT1)^2+(MAT2)^2+(MAT3)^2+(MAT4)^2+,upper=T,diag=T)) Then "1215450" values of "t"(one for
2008 Dec 15
2
how to merge list of dataframes?
Dear all: I have a list of dataframes like this, i try to merge this lists of dataframes into one single dataframe, and keep ther column names as usual, how can i do this? i try lapply(aa,rbind), but it dose not work. Best regard! > summary(aa) Length Class Mode [1,] 3 data.frame list [2,] 3 data.frame list [3,] 3 data.frame list [4,] 3 data.frame
2010 Mar 11
2
Comparing matrices
Hello all, I have two matrices, pop and pop2, each the same number of rows and columns that I want to compare for equality. I am concerned about efficiency in this operation. I've tried a few things without success so far. Doing something simple like: if (pop==pop2) { cat('equal') } else { cat('NOT equal') } results in the warning: 1: In if (pop == pop2) { : the
2009 Jan 09
2
recursive relevel
Dear list, I'm having second thoughts after solving a very trivial problem: I want to extend the relevel() function to reorder an arbitrary number of levels of a factor in one go. I could not find a trivial way of using the code obtained by getS3method("relevel","factor"). Instead, I thought of solving the problem in a recursive manner (possibly after reading
2010 Sep 06
2
rbind() overwriting data.frame()
Hi, first off, I wanna ask how do I declare a data.frame of 0 rows and n columns? Coming to my problem, I have a data.frame of 22 columns by dynamic rows which I insert using rbind. The total number of rows could go upto 2,00,000. The problem is that after about 800 or 900 get inserted rbind starts overwriting the data.frame and I end up with a total of 800-900 rows. What is up with that? The
2013 Jan 23
4
to check if a character string is in a group of character strings
Hello, How can I judge if a string is in a group of string? For example, I would like to have if (subpool in pool){ }else{ } Where > pool = c("s1","s2") > subpool = c("s1") How can I write the "subpool in pool" right in R? Thanks very much! Cheers, Rebecca ---------------------------------------------------------------------- This message,
2010 Apr 29
5
reduce size of pdf
is there a way to reduce the size of pdf files in R: ? compression? lower dpi ? or some other option?
2008 Dec 16
1
Prediction intervals for zero inflated Poisson regression
Dear all, I'm using zeroinfl() from the pscl-package for zero inflated Poisson regression. I would like to calculate (aproximate) prediction intervals for the fitted values. The package itself does not provide them. Can this be calculated analyticaly? Or do I have to use bootstrap? What I tried until now is to use bootstrap to estimate these intervals. Any comments on the code are welcome.
2012 Jun 29
5
assign object with loop (translation from SAS to R)
I have a dataset named DM with p1, p2, ...., p9 (9 columns, numerical values) I would like to calculate to multify each pair of columns (p1p2, p1p3,... p1p9, p2p3, p2p4.... p8p9) and assign them in p1p2, p1p3,... p1p9, p2p3, p2p4.... p8p9 In SAS, l=0; p_int_sum=0; do i=1 to 8; do j=(i+1) to 9; l=l+1; p{i}p{j}=p{i}*p{j}; end; end; I would like to know how to assign them in R I tried for
2010 Aug 30
1
compare three values
Hi, I've three values. What is the best method to choice the lowest values with an if function? example: a = 3 b = 1 c = 5 if (lowest(a,b,c) is a) {........} if (lowest(a,b,c) is b) {........} if (lowest(a,b,c) is c) {........} Thanks, Alfredo
2009 Jan 14
3
Logical function to turn missing values to 0's
I have a dataset which contains some missing values, and I need to replace them with zeros. I tried using the following: x <- matrix(data=rep(c(1,2,3,NA),6), ncol=6, nrow=6) y <- matrix(data=0, ncol=ncol(x), nrow=nrow(x)) for(i in 1:nrow(x)) { for(j in 1:ncol(x)) { y[i,j] <- ifelse(x[i,j]==NA, 0, x[i,j]) }} But y returns an NA matrix. I'd appreciate any help. -- View this