R语言 字符串写入文件

发布时间:2020-07-26 10:26:48 作者:qizok
来源:网络 阅读:1813
out_con <- file("out.txt", "w")
write(sprintf("This is line %d.\n",1),out_con,append=T)
write("This is line 2.",out_con,append=T)
close(out_con)


或者

printer = file("out.txt","w")
writeLines("This is line.",con=printer,sep=" ")
writeLines("The same line.",con=printer)
close(printer)

参考:

http://grokbase.com/t/r/r-help/137hry3mga/r-writing-multiple-lines-to-a-file


也可以用sink

sink("tmp_out.txt")
con <- file("raw.txt", "r")
line <- readLines(con, n=1)
while(length(line) != 0) {
   c = unlist(strsplit(line, "\t"))
   if (c[1] == "Contig") {
          #k_test <- rbind(k_test, c)
          cat(line)
          cat("\n")
   }
   else if (as.numeric(c[1]) %in% g.out$name) { 
         ##a <- sapply(c, as.numeric)
         ##k_test <- rbind(k_test, a)
         cat(line)
         cat("\n")
   }
   line = readLines(con, n=1)
}
close(con)
sink()


推荐阅读:
  1. R语言笔记
  2. R语言取子集

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

r 写入 文件

上一篇:华为RH2288H V3服务器raid配置与系统安装

下一篇:OpenStack架构----neutron组件(四)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》