作者wertymin24 (werty)
看板Statistics
标题[程式] R的资料转换
时间Wed Mar 23 21:48:06 2011
------------------------------------------------------------------------
[软体程式类别]:
R
[程式问题]:
资料处理
[软体熟悉度]:
中(3个月到1年)
[问题叙述]:
我有一笔资料如下图
Tree 1924 1934 1935 1936 ~ 2000
1 12 20 21 22 40
2 11 18 20 23 50
3 10 14 15 =>1935後是空白
4 10 16 25 23 =>1936後是空白
5
~
~
1000 9 18 23 24 46
想要转换成
Tree year dbh
1 1924 12
1 1934 20
1 1935 21
1 1936 22
~ ~ ~
1 2000 40
2
2
2 ~ ~
~
~
1000 2000 46
我目前是用reshape的方式
但是他会跑出一串错误如下
"Error in is.null(arg) : 'arg' is missing"
我GOOGLE没有找到类似的问题,是因为我有空白值吗?
但我将空白值填入0後一样,而且我看reshape的example里空白值会自动填入NA才对
[程式范例]:
data <- reshape(temp,idvar='Tree',timevar='dbh',
varying=list(c('1924',''1934','1935','1936','2000',direction='long')))
-----------------------------------------------------------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.45.187.249
1F:→ clickhere:老实说,用几个for回圈写一写比用现成的package也许有效 03/23 22:02
2F:→ clickhere:率. 光是看help,example,贴文,等回答的时间... 03/23 22:03
3F:→ wertymin24:因为我不太会用回圈... 03/23 22:11
4F:→ rockken:一个FOR 就OK了。 03/23 22:15
5F:→ rockken:你急吗?? 我程式放学校。 明天再贴给你? 03/23 22:17
6F:→ wertymin24:喔喔~感谢楼上 03/23 22:30