从具有特定固定宽度格式的数据帧创建txt文件 [英] Creating txt file from a dataframe with specific fixed-width format

查看:64
本文介绍了从具有特定固定宽度格式的数据帧创建txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为dfGL的数据帧,具有22列和17000行! 行名称为:pressurediameterroughness ...

I have a data frame called dfGL with 22 columns and 17000 rows! The row names are: pressure, diameter, roughness...

我想从该数据框中创建一个txt文件,例如:

I want to create a txt file from this data frame such that:

  • dfGL的第一列从文本文件的位置1开始(第1行第1列),
  • 第二列从位置25(第1行第25列)开始,
  • 第3列从位置50(第1行第50列)开始,
  • 等等! 在此处输入图片描述
  • 1st column of dfGL starts from position 1 of the text file (Line 1 Column 1),
  • 2nd column starts at position 25 (Line 1 Column 25),
  • 3rd column starts at position 50 (Line 1 Column 50),
  • and so on! enter image description here

推荐答案

这是有效的解决方案:

dfGL<-rbind(colnames(dfGL),dfGL)

dfGL<- rbind( colnames(dfGL) , dfGL)

write.fwf(dfGL,file = paste("Inpuuuttt",".txt",sep ="),width = 25,rownames = T,colnames = F,quote = F)

write.fwf(dfGL, file = paste("Inpuuuttt", ".txt", sep = ""),width = 25,rownames = T,colnames = F, quote = F )

这篇关于从具有特定固定宽度格式的数据帧创建txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆