Dear All,
Thanks in advance for any help. I have a square matrix of measures of
interactions among individuals and would like to calculate a values from a
function (colSums for example) with a single individual (row) excluded in
each instance. That individual would be returned to the matrix before the
next is removed and the function recalculated. I can do this by hand
removing rows based upon ids however I would like specify individuals to be
removed from a list (lots of data).
An example matrix:
MyMatrix
E985047 E985071 E985088 F952477 F952478 J644805 J644807 J644813 E985047
1 0.09 0 0 0 0 0 0.4 E985071 0.09 1 0 0 0 0 0 0.07 E985088 0 0 1 0 0 0
0.14 0 F952477 0 0 0 1 0.38 0 0 0 F952478 0 0 0 0.38 1 0 0 0 J644805 0 0
0 0 0 1 0.07 0 J644807 0 0 0.14 0 0 0.07 1 0 J644813 0.4 0.07 0 0 0 0 0 1
Example list of individuals to be removed
MyList
E985088
F952477
F952478
If I were to do this by hand it would look like
MyMat1 <- MyMatrix[!rownames(MyMatrix)%in% "E985088",]
colSums(MyMat1)
MyMat2 <- MyMatrix[!rownames(MyMatrix)%in% " F952477 ",]
colSums(MyMat2)
MyMat3 <- MyMatrix[!rownames(MyMatrix)%in% " F952478 ",]
colSums(MyMat3)
How might I replace the individual ids (in quotes) with a list and remove
rows corresponding to that list from the matrix for the calculation and
returning the row to the list after each calculation before the next.
I hope I've been clear!!
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.