- 在Excel中欠拾,粘貼選項中數(shù)據(jù)轉(zhuǎn)置功能。
- 在R中骗绕,使用t()進行數(shù)據(jù)轉(zhuǎn)置藐窄。
- 在STATA中,也有類似功能酬土。由xpose命令實現(xiàn)荆忍。
- 注意,reshape命令實現(xiàn)的是長寬表的轉(zhuǎn)換撤缴, 不是行列轉(zhuǎn)置刹枉。
xpose語法
xpose, clear [options]
options Description
-------------------------------------------------------------------------------
* clear 必選項。注意腹泌,如果原始數(shù)據(jù)未保存嘶卧,將會丟失。
format 使用原始數(shù)據(jù)的最大數(shù)字顯示格式
format(%fmt) 定義轉(zhuǎn)置后數(shù)據(jù)所有變量的格式
varname 添加變量 _varname保存原始數(shù)據(jù)中的變量名
promote 使用保持數(shù)字準確性的最緊湊數(shù)據(jù)類型
---------------------------------------------------------------------------------
* clear is required.
示例
. webuse xposexmpl, clear
. describe
Contains data from http://www.stata-press.com/data/r15/xposexmpl.dta
obs: 3
vars: 4 8 Jan 2016 08:25
size: 48
--------------------------------------------------------------------------
storage display value
variable name type format label variable label
--------------------------------------------------------------------------
county float %9.0g
year1 float %5.0g
year2 float %6.0g
year3 float %9.0g
--------------------------------------------------------------------------
Sorted by:
. xpose, clear varname format
. describe
Contains data
obs: 4
vars: 4
size: 80
--------------------------------------------------------------------------
storage display value
variable name type format label variable label
--------------------------------------------------------------------------
v1 float %9.0g
v2 float %9.0g
v3 float %9.0g
_varname str8 %9s
--------------------------------------------------------------------------
Sorted by:
Note: Dataset has changed since last saved.
. list
-------------------------------
v1 v2 v3 _varname
-------------------------------
1. 1 2 3 county
2. 57.2 12.5 18 year1
3. 11.3 8.2 14.2 year2
4. 19.5 28.9 33.2 year3
-------------------------------