将 "NA" 字符串更改为 -99.99
Change "NA" strings to -99.99
我正在尝试将我的数据帧列表中的 NA 字符串替换为 -99.99,以便 运行 我在 RCLIMDEX 中的数据。
这是我的一个数据框的结构,它们的列数和行数都相同 header。
year month day Pr Tx2m Tn2m
1 1987 12 31 NA NA NA
2 1988 1 1 0 NA NA
3 1988 1 2 0 NA NA
4 1988 1 3 0 NA NA
5 1988 1 4 0 NA NA
6 1988 1 5 0 NA NA
我试过使用以下方法:
estaciones <- lapply(estaciones, function(x) {x[x==is.na] <- "-99.99"; return(x)})
和
estaciones <- lapply(estaciones, function(x){
x[, 'is.na'] <- -99.99
return(x)
})
这两行都没有 return 我的数据框替换了 -99.99 值,它们仍然是 NA。
我可以用什么将 NA 字符串替换为 -99.99?谢谢
is.na
是一个函数,它应该应用于这些变量。
estaciones[] <- lapply(estaciones, function(x) {
x[is.na(x)] <- "-99.99"
return(x)})
或者简单地对整个数据应用 is.na
以创建一个逻辑矩阵,使用它来对原始数据进行子集化并将这些值分配给 -99.99
estaciones[is.na(estacioes)] <- "-99.99"
我正在尝试将我的数据帧列表中的 NA 字符串替换为 -99.99,以便 运行 我在 RCLIMDEX 中的数据。
这是我的一个数据框的结构,它们的列数和行数都相同 header。
year month day Pr Tx2m Tn2m
1 1987 12 31 NA NA NA
2 1988 1 1 0 NA NA
3 1988 1 2 0 NA NA
4 1988 1 3 0 NA NA
5 1988 1 4 0 NA NA
6 1988 1 5 0 NA NA
我试过使用以下方法:
estaciones <- lapply(estaciones, function(x) {x[x==is.na] <- "-99.99"; return(x)})
和
estaciones <- lapply(estaciones, function(x){
x[, 'is.na'] <- -99.99
return(x)
})
这两行都没有 return 我的数据框替换了 -99.99 值,它们仍然是 NA。
我可以用什么将 NA 字符串替换为 -99.99?谢谢
is.na
是一个函数,它应该应用于这些变量。
estaciones[] <- lapply(estaciones, function(x) {
x[is.na(x)] <- "-99.99"
return(x)})
或者简单地对整个数据应用 is.na
以创建一个逻辑矩阵,使用它来对原始数据进行子集化并将这些值分配给 -99.99
estaciones[is.na(estacioes)] <- "-99.99"