I'm doing if condition and I want to match values from 2 different columns and of they match it has to assign value to another column. when I write the statement
for (l in 1:k) {
for(i in 1:n) {
if(y_related[i,2]==con_f[l]) {
y_out[l]=y_related[i,1]
}
}
}
then it doesn't work! but if I replaced the con_f with it's numerical value say 0.004 then it works. but I wanted to run it automatically as I don't want to write the numerical value every time!!
detailed example:
y_related=matrix(NA,1000,2)
y_related[,1]=rnorm(1000,5,10)
y_related[,2]=rank(y_related[,1])/1000
con_f=matrix(NA,250,1)
for(x in 1:250) {
con_f[x]=(1-((x-1)/250))
}
y_out=matrix(NA,250,1)
for (l in 1:250) {
for(i in 1:1000) {
if(y_related[i,2]==con_f[l]) {
y_out[l]=y_related[i,1]
}
}
}