The error message 'Error in apply(world[, 5:16], function(x) x/world$exact_extract.crop_area..world...sum..) : argument 'FUN' is missing, with no default' suggests that the 'FUN' argument is missing in the apply function. The 'FUN' argument specifies the function to be applied to each column or row of the data.

To fix the error, you need to specify a function for the 'FUN' argument. For example, if you want to divide each element in the selected columns by the sum of the crop area, you can use the following code:

world[, 5:16] <- apply(world[, 5:16], 2, function(x) x / sum(world$exact_extract.crop_area..world...sum..))

In this code, the 2 in the apply function specifies that the function should be applied to each column (you can use 1 for applying the function to each row). The function function(x) x / sum(world$exact_extract.crop_area..world...sum..) divides each element in the selected columns by the sum of the crop area.

Make sure to adjust the column numbers and the variable name according to your data.

R Error: 'FUN' argument missing in apply function - Solution and Explanation

原文地址: https://www.cveoy.top/t/topic/hE86 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录