Skip to content

define variables from rows of a matrix

2 messages · gallon li, Eik Vettorazzi

#
Hi,
I was irritated about your printed last row of A, which apart from
definition contains a 20. Anyway, how about this:

y<-x<-rep(NA,nrow(A))

#its not clear, whether multiple values of 100 can occur in a single
#row, and what to do, when 100 is found before and after 20, so you may
#alter the indexing as you need:

ind<-subset(merge(which(A==20,arr.ind=T),which(A==100,arr.ind=T),by="row",all.x=T),col.x<col.y|is.na(col.y))

x[ind$row]<-ind$col.x
y[ind$row]<-ind$col.y
x
y

which places an NA in x and y for all "no shows". I did not get the
logic behind setting x[3] to ">5" but x[5] to NA (same for y[3], y[4]),
so this is left for you to implement.

cheers.


Am 10.08.2011 08:15, schrieb gallon li: