Hi,
I have a matrix with numbers and character. I want to evaluate each cell and
change the value of the cell before it depending on the evaluation. My
evaluation: if a cell had the word down change the cell preceding it to a
negative number by multiplying that value by a -1. I am have trouble
Try this:
x
V1 V2 V3 V4
1 PROBE 1 2.5 UP
2 PROBE 2 1.0 UP
3 PROBE 3 1.4 DOWN
4 PROBE 4 2.0 UP
5 PROBE 5 1.3 DOWN
x$V3[which(x$V4 == DOWN) - 1] - x$V3[which(x$V4 == DOWN) - 1] * -1
On Mon, Dec 27, 2010 at 4:11 PM, R_novice kaso...@battelle.org wrote:
Hi,
I have a matrix
Thank you for the quick response :-). I've applied your suggestion to my
code, but I still receive an error:
CEM1_PARTIAL$V3[which(CEM1_PARTIAL$V4 == DOWN) - 1] -
CEM1_PARTIAL$V3[which(CEM1_PARTIAL$V4 == DOWN) - 1] * -1
Warning message:
In Ops.factor(CEM1_PARTIAL$V3[which(CEM1_PARTIAL$V4 ==
Convert your column to numeric:
CEM1_PARTIAL$V3 - as.numeric(as.character(CEM1_PARTIAL$V3))
On Mon, Dec 27, 2010 at 4:28 PM, R_novice kaso...@battelle.org wrote:
Thank you for the quick response :-). I've applied your suggestion to my
code, but I still receive an error:
That just converts my values in V3 to NA
--
View this message in context:
http://r.789695.n4.nabble.com/matrix-looping-accessing-previous-column-tp3165308p3165340.html
Sent from the R help mailing list archive at Nabble.com.
__
Using which() improves my code, but now I'm receiving some data.frame error
and still does not convert the values to negative.
#TAKE PART OF MATRIX
CEM1_PARTIAL - CEM1[1:10,1:10]
#CEM1_PARTIAL=apply(CEM1_PARTIAL,2,as.character)
#CEM1_PARTIAL - as.numeric(as.character(CEM1_PARTIAL))
6 matches
Mail list logo