R语言|ifelse的用法

ifelse returns a value with the same shape as test which is filled with elements selected from either yes or no depending on whether the element of test is TRUE or FALSE. 
ifelse 返回一个与 test 具有相同形状的值,其中填充了从 yes 或 no 中选择的元素,具体取决于 test 的元素是 TRUE 还是 FALSE。
Usage: ifelse(test, yes, no) 示例: data$col <- ifelse(is.na(data$col),data$col,data$col2)

 

posted @ 2021-12-24 09:55  西西与维奥拉  阅读(685)  评论(0)    收藏  举报