Assigning values of an object to a column in Loop through R -
this snippet of r code. trying assign value of resultsdata[i]
column error
values not assigning. results coming in console somehow not able assign required column
resultsdata=foreach(i=1:length(xyzarr)) %dopar% { xyzred[xyzsred$loopn==xyzarr[i],]$setpoint-xyzred[xyzred$loopn==xyzarr[i],]$temp } foreach(i=1:length(xyzarr)) %dopar%{ xyzred[xyzred$loopn==datapointsarr[i],]$error=resultsdata[[i]] } results in console: [[1]] [1] 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 1.186 2.266 2.266 2.266 2.266 2.266 [19] 2.266 2.266 2.266 2.266 1.384 2.392 2.392
i typically use combine feature. general approach calculate column, output entire row. lastly, row binding logic puts together.
xyzarr$var_name_here <- numeric(nrow(xyzarr)) resultsdata <- foreach(i=1:length(xyzarr), .combine=rbind) %dopar% { xyzarr[i,]$var_name_here <- xyzred[xyzsred$loopn==xyzarr[i],]$setpoint-xyzred[xyzred$loopn==xyzarr[i],]$temp xyzarr[i,] }
Comments
Post a Comment