[英]specify a character vector for row.names in write.table () r
Given the write.table line below: 给定下面的write.table行:
write.table(results,file = "mydata.csv",row.names = TRUE,col.names = TRUE,sep = ",", append = TRUE)
I have the below result: enter image description here 我得到以下结果: 在此处输入图像描述
However I would like to have row.names set up for a specific character vector (called "text" in my algorithm) to have the below result for a 400 rows (Note: Again, every row is already known. My concern is how to specify it so that my output file (mydata.csv) capture it. Please see below for desired outcome: enter image description here Please let me know if I have not been clear , and I will provide more details. Thanks a lot for your help 但是,我想为特定的字符向量(在我的算法中称为“文本”)设置row.name,以得到400行的以下结果(注意:同样,每一行都是已知的。我关心的是如何指定它以便我的输出文件(mydata.csv)捕获它。请参见下面的预期结果: 在此处输入图像描述如果不清楚,请告诉我,我将提供更多详细信息。非常感谢您的帮助
From the row.names
argument of help(write.table)
: 从
help(write.table)
的row.names
参数中:
either a logical value indicating whether the row names of
x
are to be written along withx
, or a character vector of row names to be written .指示
x
的行名是否要与x
一起写入的逻辑值, 或者是要写入的行名的字符向量 。
So you could add your row names vector text
in the row.names
argument. 因此,您可以在
row.names
参数中添加行名矢量text
。
write.table(results, row.names = text, ...)
Also note that row.names = TRUE
and col.names = TRUE
are the default values in write.table()
, so you do not need to include them. 还要注意,
row.names = TRUE
和col.names = TRUE
是write.table()
的默认值,因此您无需包括它们。 I'm also not sure why you're using append = TRUE
. 我也不确定为什么要使用
append = TRUE
。 Taking those out, your call would then be 取出这些电话,您的电话便会
write.table(results, row.names = text, file = "mydata.csv", sep = ",")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.