在Rstudio中编写代码时出现以下错误
Error: unexpected symbol in:
"dataset$Age = ifelse(is.na(dataset$Age),
ave(dataset$Age, FUN = fuction(x) mean"
> dataset$Age)
Error: unexpected ')' in " dataset$Age)"
代码如下
dataset = read.csv('Data.csv')
dataset$Age = ifelse(is.na(dataset$Age),
ave(dataset$Age, FUN = fuction(x) mean(x, na.rm = TRUE)),
dataset$Age)
任何帮助都会很棒。
答案 0 :(得分:2)
您写的是功能而不是fu n 。
dataset = list()
dataset[["Age"]] = c(10,20,30,40,50, NA)
ifelse(is.na(dataset$Age),
ave(dataset$Age, FUN = function(x) mean(x, na.rm = TRUE)),
dataset$Age)
[1] 10 20 30 40 50 30