Displaying 20 results from an estimated 70000 matches similar to: "merging two maxtrices"
2010 Jul 15
3
Summing over intervals
Given a matrix of MxN
want to take the means of rows in the following fashion
m<-matrix(seq(1,80),ncol=20, nrow=4)
result<-matrix(NA,nrow=4,ncol=20/5)
result[,1]<-apply(m[,1:5],1,mean)
result[,2]<-apply(m[,6:10],1,mean)
result[,3]<-apply(m[,11:15],1,mean)
result[,4]<-apply(m[,16:20],1,mean)
result
[,1] [,2] [,3] [,4]
[1,] 9 29 49 69
[2,] 10 30 50 70
2010 Jun 10
2
counting Na/not NA by groups by column
# create a matrix with some random NAs in it
> m<-matrix(NA,nrow=15,ncol=14)
> m[,3:14]<-52
> m[13,9]<-NA
> m[4:7,8]<-NA
> m[1:2,5]<-NA
> m[,2]<-rep(1800:1804, by=3)
> y<-order(m[,2])
> m<-m[y,]
> m[,1]<-rep(1:3,by=5)
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[,14]
[1,] 1 1800 52 52 NA 52 52
2009 Jul 15
1
problem with merging matrices
Dear all,
I'm a relative new user of R and I have a problem with merging a collection
of matrices. All matrices in this collection have the same dimension (532
rows and 532 columns), but can differ in the row and columns names. I'd like
to merge these matrices in such a way that the resulting matrix only
contains unique row- and column-names and that in case of a match between
the row or
2013 Jan 10
1
merging command
HI Eliza,
You could do this:
set.seed(15)
mat1<-matrix(sample(1:800,124*12,replace=TRUE),nrow=12) # smaller dataset
#Your codes
?list1<-list()
?for(i in 1:ncol(mat1)){
? list1[[i]]<-t(apply(mat1,1,function(x) x[i]-x))
? list1}
?x<-list1??
x<-matrix(unlist(x),nrow=12)
x<-abs(x)
?y<-colSums(x, na.rm=FALSE)
z<-matrix(y,ncol=10)
?z<-as.dist(z)
?z
?# ?? 1?? 2?? 3?? 4?? 5??
2009 Sep 18
1
merging data frames with matrix objects when missing cases
Hi,
I have faced a problem with the merge() function when trying to merge
two data frames that have a common index but the second one does not
have cases for all indexes in the first one. With usual variables R
fills in the missing cases with NA if all=T is requested. But if the
variable is a matrix R seems to insert NA only to the first column of
the matrix and fill in the rest of the columns by
2006 May 30
2
merging
Dear List,
Given,
y <- matrix(c(0,1,1,1,0,0,0,4,4), ncol = 3, byrow = TRUE)
rownames(y) <- c("a","b","c")
colnames(y) <- c("1","2","3")
y
y2 <- y[2:3, ]
rownames(y2) <- c("x","z")
y2
how can I stop
merge(y, y2, all = TRUE, sort = FALSE)
squishing the extra rows? Ideally I want the same as:
rbind(y,
2011 Jul 27
2
Elegant way to subtract matrix from array
there are really two related problems here
I have a 2D matrix
A <- matrix(1:100,nrow=20,ncol =5)
S <- matrix(1:10,nrow=2,ncol =5)
#I want to subtract S from A. so that S would be subtracted from the
first 2 rows of
#A, then the next two rows and so on.
#I have a the same problem with a 3D array
# where I want to subtract Q for every layer (1-10) in Z
# I thought I solved this one
2010 Oct 15
7
Problem with merging two zoo objects
Dear all, I have following 2 zoo objects. However when I try to merge those 2 objects into one, nothing is coming as intended. Please see below the objects as well as the merged object:
> dat11
V2 V3 V4 V5
2010-10-15 13:43:54 73.8 73.8 73.8 73.8
2010-10-15 13:44:15 73.8 73.8 73.8 73.8
2010-10-15 13:45:51 73.8 73.8 73.8 73.8
2010-10-15 13:46:21 73.8 73.8 73.8 73.8
2010 Apr 25
3
Noobie question on aggregate tapply and by
I have a 43MB dataframe ( 5 variables) and I'm trying to summarize subsets
of the data.
I've RTFM ( not very clear) and looked at a variety of samples but cant seem
to figure out
how to make these functions work.
A sample of what I want to do would be this:
ids<-seq(1,50)
years<-c(rep(5,10),rep(6,10),rep(7,10),rep(8,20))
2011 Nov 28
1
code problem with the optim() function
Please forgive me if someone has seen this duplicated email, because I sent
the email to the wrong address just now.
Hi, all,
I'm estimating an inter-rater coefficient, Aickin (1990)'s alpha. It's been
a long time for me to figure out how to make it work, but it's still of no
avail. The problem seems to be my code with the optim() function. Can
anyone help me take a look at the
2010 Apr 18
2
Calculating a Maximum for a row or column with NA's
Is there a simple way to calculate the maximum for a row or column of a
matrix when there are NA,s present.
# given a matrix that has any number of NA per row
> m<-matrix(c(seq(1,9)),nrow=3)
> m
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> m[3,1]=NA
> m[1,]=NA
> m
[,1] [,2] [,3]
[1,] NA NA NA
[2,] 2 5 8
[3,] NA 6 9
2009 Jul 13
4
Combine two matricies
Hi,
I have two matricies a and x:
a<-matrix(c(3,4,5,2,3,4,1,1,2), nrow=3, ncol=3)
[,1] [,2] [,3]
[1,] 3 2 1
[2,] 4 3 1
[3,] 5 4 2
x<-matrix(c(3, NA, NA, NA, 2, 5, NA, 2, 2), nrow=3, ncol=3)
[,1] [,2] [,3]
[1,] 3 NA NA
[2,] NA 2 2
[3,] NA 5 2
I wish to combine these two into one matrix using the values from x where x has values, and
2009 Aug 27
1
Problem merging two data frames
Hello everyone,
Merging two dataframes should be easy. However when I try to merge, R
doesn't recognize identical values, even if I am doing it by values that
have no decimals.
willclayong:
vs30 LON LAT Net X wills.cat wills.vs30 clahan.cat clahanvs30
PolyID.wills PolyID.clahan tif.cat STA ELEVATION tif.vs30
1 338.539 -3849590 4319319 <NA> 2 D 301
2005 Feb 21
5
Compare rows of two matrices
Hello,
#I have two matrices, eg.:
y <- matrix( c(20, NA, NA, 45, 50, 19, 32, 101, 10, 22, NA, NA, 80, 49, 61, 190), ncol=4 )
x <- matrix( c(20, NA, NA, NA, 50, 19, 32, 101, 10, 22, NA, NA, 80, 49, 61, 190), ncol=4 )
#Whereas x contains all NA?s from y plus some additional NA?s.
#I want to find the index of these additional NA?s. I think, there must be a very
2008 Dec 19
2
Merging data frames of different length
Hello, everyone!
I have list L that contains 99 data frames. All data frames have only
one row, but a different number of columns. Some data frames have 3
columns, some - 6 columns, and some - 9 columns. The names of the
first 3 columns are identical in all 99 data frames (e.g., A, B, and
C). The names of columns 4:6 are identical in data frames that contain
6 and 9 columns (e.g., D, E, and F).
2006 Dec 07
1
Merging two data sets
Dear all R users,
Suppose I have two datasets:
g =
8/11/2005 92.75
9/11/2005 92.30
10/11/2005 92.55
11/11/2005 93.90
11/14/2005 94.20
11/15/2005 94.40
11/16/2005 93.90
11/22/2005 94.60
11/24/2005 95.50
2/12/2005
2007 Oct 11
2
Matching and merging two rows with missing values
Hello,
I have two rows which are almost identical but miss different values at
different locations. I would like to merge these two rows so that the
missing values are replaced by the element in the same column on the other
row making one row. If both rows contain a NA, NA remains in the output.
1 2 3 4 5
Row1 AA AG GG NA NA
Row2 NA AG GG AA NA
The
2011 Sep 16
2
problems to report indexes when I have two min value
Hi,
I need to repor the index of a min value of each row in a matrix, but I
don't know how to do that when I have more than one min value.
Here is my example
> dat <-
matrix(c(5.4,4.8,5.6,4.8,NA,4.4,4.6,3.4,NA,NA,4,2.4,NA,NA,NA,2),byrow=TRUE,ncol=4)
> dat
[,1] [,2] [,3] [,4]
[1,] 5.4 4.8 5.6 4.8
[2,] NA 4.4 4.6 3.4
[3,] NA NA 4.0 2.4
[4,] NA NA NA 2.0
2003 Sep 03
2
lme in R and Splus
Good Day,
Included below is some code to generate data and to fit a mixed effects
model to this fake data. The code works as expected when I call the
function "lme" in Splus but not in R.
The error message from calling lme in R is:
"Error in getGroups.data.frame(dataMix, groups) :
Invalid formula for groups"
I installed the nlme package for R around 20 August
2012 Mar 21
2
Check results between two data.frame
Dear R-user,
I'm trying to compare two sets of results and wanted to find out which
element in the two data frame/matrix are different.
I wrote the following function and it works ok, and gives me a long list of
"good" as outcomes.
CHECK<-
function (x = "file1", y = "file2")
{
for (i in 1:nrow(x)) {
for (j in 1:ncol(x)) {
if (x[i, j]