[R] threshold and replace values in a matrix

Alaios alaios at yahoo.com
Wed Oct 21 15:34:48 CEST 2015


Dear all I have a table as that.
test<-matrix(data=rnorm(100),ncol=10)
and I want to find the values that are below my thresholdthreshold<- -0.5and replace them with a -1 instead.

I can of course write a double nested for loop to check one by one elementif (test[i,j]<= threshold)   test[i,j]<- -1
but that would be rather inneficient sice I have very large tables.
Does R offer any "automation" for matrix data types?
I would like to thank you in advance for your replyRegardsAlex

	[[alternative HTML version deleted]]



More information about the R-help mailing list