我有一个xts
对象(df
):
## a b
## 2015-09-14 -0.5470 NA
## 2015-09-15 0.0112 NA
## 2015-09-16 0.0910 0.932
## 2015-09-17 -Inf 0.862
## 2015-09-18 Inf 1.946
## 2015-09-21 -0.7050 2.692
## 2015-09-22 NaN 2.011
## 2015-09-23 -0.5440 1.859
## .
## .
## etc
由于列a
包含Inf
,-Inf
和NaN
,我收到了一些错误。有没有办法用NA
替换这些值(将Inf
和NaN
视为缺失值)?
答案 0 :(得分:3)
您可以像普通<select class='filter_class' name="filter"
data-userid="29" >
<option value="all">All</option>
<option value="asc">Asc</option>
<option value="desc">Desc</option>
</select>
<select class='filter_class' name="filter"
data-userid="30" >
<option value="all">All</option>
<option value="asc">Asc</option>
<option value="desc">Desc</option>
</select>
<script>
$(".filter_class").change(function(){
var user_id = $(this).data('userid');
alert(user_id);
})
</script>
apply
使用您提供的数据:
matrix
另一种方法是通过索引要保留(或删除)
的元素来进行替换d <- xts(read.zoo(text='date a b
2015-09-14 -0.5470 NA
2015-09-15 0.0112 NA
2015-09-16 0.0910 0.932
2015-09-17 -Inf 0.862
2015-09-18 Inf 1.946
2015-09-21 -0.7050 2.692
2015-09-22 NaN 2.011
2015-09-23 -0.5440 1.859', header=T, index=1))
apply(d, 2, function(x) ifelse(is.finite(x), x, NA))
## a b
## 2015-09-14 -0.5470 NA
## 2015-09-15 0.0112 NA
## 2015-09-16 0.0910 0.932
## 2015-09-17 NA 0.862
## 2015-09-18 NA 1.946
## 2015-09-21 -0.7050 2.692
## 2015-09-22 NA 2.011
## 2015-09-23 -0.5440 1.859