a is a dataframe and I want to update 0 values in dataframe from some previous values and as soon as a 0 value is updated , I also want to update the bottom rows with zero values to that updated value. It is dependent on some relationship between rows and columns
. But, I am stuck and get this error Error in x[[jj]][iseq] <- vjj : replacement has length zero.
Also I am attaching a picture of the dataframe a. R programming.
a[1,2] should be replaced by a[2,1] and then if any of these are zeroes(a[4,1], a[4,2], a[8,1], a[8,2]), they take value of updated a[1,2].
Code
a=data.frame(c(1.1,0,3,0,4,0,7,8),c(9,8.4,0,9,7,0,6,0))
print(a)
for (j in 1:ncol(a))
{for( i in 1:nrow(a))
{
if(j%%2==1)
{if(i%%2==0)
{if(a[i,j]==0)
a[i,j]=a[i/2,j]
###
while(i<=63)
{
a[i*2,j]=a[i/2,j]
a[i*2,j+1]=a[i/2,j]
i=i*2
}
###
}
else if (i%%2==1)
{if(a[i,j]==0)
a[i,j]=a[floor(i/2),j+1]
while(i<=63)
{
a[i*2,j]=a[floor(i/2),j]
a[i*2,j+1]=a[floor(i/2),j]
i=i*2
}
}
}
else if(j%%2==0)
{if(i%%2==0)
{if(a[i,j]==0)
a[i,j]=a[i/2,j-1]
while(i<=63)
{
a[i*2,j]=a[i/2,j-1]
a[i*2,j+1]=a[i/2,j-1]
i=i*2
}
}
else if (i%%2==1)
{if(a[i,j]==0)
a[i,j]=a[floor(i/2),j]
while(i<=63)
{
a[i*2,j]=a[floor(i/2),j]
a[i*2,j+1]=a[floor(i/2),j]
i=i*2
}
}
}
}
}