如何保存到R中的文件label()输出?

时间:2014-11-11 14:25:01

标签: r

数据变量中有一个对象列表。

我打电话(图书馆:Hmisc):

label(data)

输出:

$SubsID
NULL

$SubsID_RN
NULL

$responseid
NULL

$Wave
2014   2013   2012 
"2014" "2013" "2012" 

$Country
 Hong Kong         Taiwan          Chile      Singapore    New Zealand 
      "46"           "45"           "44"           "43"           "42" 
   Finland   Saudi Arabia         Israel    Netherlands        Belgium 
      "41"           "40"           "39"           "38"           "37" 
   Tunisia   South Africa       Malaysia         Mexico         Canada 
      "36"           "35"           "34"           "33"           "32" 
  Portugal    Switzerland       Columbia      Venezuela         Brazil 
      "31"           "30"           "29"           "28"           "27" 
 Argentina            UAE         Turkey          India        Austria 
      "26"           "25"           "24"           "23"           "22" 
     Japan          China      Australia        Ireland     UK (Welsh) 
      "21"           "20"           "19"           "18"           "17" 
  Thailand    South Korea         Russia         Poland Czech Republic 
      "16"           "15"           "14"           "13"           "12" 
   Hungary         Greece         Norway        Denmark         Sweden 
      "11"           "10"            "9"            "8"            "7" 
     Spain        Germany          Italy         France            USA 
       "6"            "5"            "4"            "3"            "2" 
        UK 
       "1" 

并希望将其写入文件。使用此命令:

write.table(label(data), "labels.txt")

我收到了错误。

Error in data.frame(SubsID = NULL, SubsID_RN = NULL, responseid = NULL,  : 
arguments imply differing number of rows: 0, 46, 3, 9, 18, 13, 50, 5, 23, 2,
12, 7,    8, 4, 6, 20, 11, 10

有什么想法吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

如果要将R函数的打印输出写入文件,请使用sink:

 > sink("output.txt")
 > label(data) # nothing appears
 > sink()  # reset output to screen