Displaying 12 results from an estimated 12 matches for "newmatrix".
2012 Jul 12
3
Add row into a Matrix witout headers from Function
Hi,
Here i have a matrix like this,
OLDMatrix <-
X1 X2 X3
----- ------ ------
22 24 23
25 27 27
10 13 15
the thing is,
im running two function(SUM,COUNT) to get output in another matrix called
NEWMatrix
NEWMatrix <- c("SUM",colSums(OLDMatrix ))
NEWMatrix <- c("COUNT",colSums(!is.na(OLDMatrix )))
Actually i need to get output like this,
NEWMatrix <-
SUM 57 64 65
COUNT 3 3 3
Instead of getting out put like above, new row gettin...
2007 Aug 24
1
uneven list to matrix
...2]]
A 1
C 3
D 4
alph[[3]]
A 1
D 4
E 5
I would like to create a matrix from the elements in the list with n
columns such that the row names are preserved and NAs are inserted into
the cells where the uneven lists do not match up based on their row names.
Here is an example of the desired output:
newmatrix
[,1] [,2] [,3]
A 1 1 1
B 2 NA NA
C 3 3 NA
D 4 4 4
E NA NA 5
Any suggestions?
I have tried
do.call("cbind",list)
I also thought I was on the right track when I tried converting each
element into a vector and then running this loop (which ultim...
2007 Feb 27
5
Multiple conditional without if
...atrix which has about 500 rows and 6 columns.
now i want to kick some data out.
i want create a new matrix which is basically the old one except for all
entries which have a 4 in the 5 column AND a 1 in the 6th column.
i tried the following but couldnĀ“t get a new matrix, just some wierd
errors:
newmatrix=oldmatrix[,2][oldmatrix[,5]==4]&&oldmatrix[,2][oldmatrix[,6]
==1]
all i get is:
numeric(0)
does anybody have an idea how to fix this one ?
thx in advance
matthias
[[alternative HTML version deleted]]
2005 Apr 21
1
large matrix
Dear R-users
I need to convert a matrix with three columns in a new array with
multiple columns.
For example,
oldmatrix
1 4 5
1 54 52
1 9 43
2 32 5
2 54 6
2 76 6
3 54 54
3 543 7
3 54 6
newmatrix
5 5 54
52 6 7
43 6 6
if the first column have a new value then add a column to the new
matrix and the new[i,j] <- old[,3][i]
I write this code, but my initial matrix is very large and the
convertion is very slow. How I can optimise that code?
converter <- function(oldmatrix) {...
2010 Jan 08
2
A better way to Rank Data that considers "ties"
...Rank
Bob 2 5
Frank 3 4
Joe 5 2
Jim 4 3
David 6 1
I have managed to do this in the following steps:
Unranked<-rownames(OriginalMatrix)
Ranked<-names(sort(OriginalMatrix,decreasing=T))
Matched<-match(Unranked,Ranked)
NewMatrix<-cbind(OriginalMatrix,Matched)
This is not acceptable, however, if two people have the same number of
apples.
You will get:
NewMatrix
Apples Rank
Bob 2 5
Frank 2 4
Joe 5 2
Jim 4 3
David 6 1
Does anyone know of a way t...
2004 Sep 29
1
glm.fit and predict.glm: error ' no terms component'
Hi
when I fit a glm by
glm.fit(x,y,family = binomial())
and then try to use the object for prediction of newdata by:
predict.glm(object, newdata)
I get the error:
Error in terms.default(object) : no terms component
I know I can use glm() and a formula, but for my case I prefer
glm.fit(x,y)...
thanks for a hint
christoph
$platform
[1] "i686-pc-linux-gnu"
$arch
[1]
2007 Sep 14
1
Copying row names
...ave been trying to copy the row names of one matrix to another matrix but
having difficulty. The original matrix contains a row name which I would
like to replicate in the new matrix. I use the following approach?
The two matrices have identical dimensions.
rN <- row.names(origMatrix)
row.names(newMatrix) <- rN
However the new matrix does not take on the labels.
I have also tried,
row.names(newMatrix) <- as.character(rN)
Any ideas?
--
View this message in context: http://www.nabble.com/Copying-row-names-tf4445280.html#a12683702
Sent from the R help mailing list archive at Nabble.com.
2010 Jan 28
2
NA Replacement by lowest value?
...nonNeg = as.data.frame(apply(orig.df, 2, function(col) # Change negative values to a small value, close to zero
{
min.val = min(col[col > 0])
col[col < 0] = (min.val / 10)
col # Column index
}))
I think this is how to start, but the NA replacement part doesn't work...
newMatrix = as.matrix(apply(oldMatrix, 2, function(col)
{
min.val = min(mData, na.rm = T) # Find the smallest value in the dataset
col[col == NA] = (min.val / 10) # Doesn't work...
col # Column index
}
Does any of you have any suggestions?
Best regards,
Joel
__...
2005 Dec 08
3
Reshaping data
Dear all,
given I have data in a data.frame which indicate the number of people in
a
specific year at a specific age:
n <- 10
mydf <- data.frame(yr=sample(1:10, size=n, replace=FALSE),
age=sample(1:12, size=n, replace=FALSE),
no=sample(1:10, size=n, replace=FALSE))
Now I would like to make a matrix with (in this simple example)
10 columns (for the
2011 Jun 16
1
Matching vector order by indicators in a matrix
Hi all~
I have a bit of stupid question. And I promise, I have struggled through this and it sort of pains me to post this question...
I have the following vector which is are the estimated parameter values output from "optim".
$Rates
[1] 0.006280048 0.330934659
I want to match the order in the vector by the number in the following matrix:
$Index.matrix
ALPHA 1 1
BETA 2
2013 Oct 15
1
Problem with lapply
...rror messages like
Error in paste(firm.names[firm.names == x], Market) :
object 'Market' not found
or (when I attach dataset)
Error in parse(text = x) : <text>:1:6: unexpected numeric constant
1: PAXN NA
(Next step would have been something like
for(i in 1:ncol(cor.results1)){
newmatrix[1,i]= cor.results1 [[i]]$estimate}
etc)
Could you please help me?
Thank you so much!
Rissa
Testcor.txt <http://r.789695.n4.nabble.com/file/n4678290/Testcor.txt>
--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-lapply-tp4678290.html
Sent from the R help maili...
2005 Mar 18
2
logistic model cross validation resolved
...ist[i], ]))
}
# determine root mean squared error
ee <- errorest(form, mdata, estimator='cv', model=myglm, est.para=control.errorest(list.tindx = cc))
# determine misclassification error
# first convert to factor
width = length(mdata)
response <- as.factor(as.integer(mdata[[rpos]]))
newmatrix <- data.frame(cbind(mdata[1:(rpos-1)], response, mdata[(rpos+1):width]))
newform <- as.formula(paste('response ~ ', as.character(form)[[3]]))
me <- errorest(newform, newmatrix, estimator='cv', model=myglm, predict=myfacpred, est.para=control.errorest(list.tindx = cc))
ret...