R语言ifelse

#输入文件下载地址 https://zenodo.org/record/2530282#.XYPNfmkzZ9B (拟南芥)
pub_df <- read.table("Locus_Published_20170630.txt",sep="\t",header=F,quote="",stringsAsFactors=F)
colnames(pub_df) <- c("name","reference_id","pubmed_id","publication_year")

#循环判断在R语言中运行非常慢!
a <- data.frame()
for (i in 1:nrow(pub_df)){if(pub_df[i,3]=="NULL" | is.na(pub_df[i,3]) | is.null(pub_df[i,3])){pub_df[i,3] <- ""; a <- rbind(a,pub_df[i,])}else{a <- rbind(a,pub_df[i,])}}
pub_df <- a

#向量化函数,速度很快!用法:ifelse(test, yes, no)
pub_df[,3] <- ifelse((is.na(pub_df[,3]) | is.null(pub_df[,3]) | pub_df[,3] == "NULL"),"",pub_df[,3])
此条目发表在R分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud