作者goodparent1 (豆芽先生)
看板R_Language
标题[问题] txt档如何直转横
时间Mon Oct 28 23:14:10 2013
[问题类型]:
程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来)
[软体熟悉度]:
新手(没写过程式,R 是我的第一次)
[问题叙述]:
例如档案
name time price
A 2000/01/31 -1
A 2000/02/29 2
A 2000/03/31 -3.3
。
。
A 2010/12/31 5
。
。
E 2010/12/31 7
。
。
Z 2010/12/31 -2
转换成这种格式而且负数变成正数
A.price 。。 E.price。。Z.price
2000/01/31 1 5 1
2000/02/29 2 5 2
2000/03/31 3.3 6 3.5
。 。 。 。
。 。 。 。
2010/12/31 5 7 2
[程式范例]:
x<-read.table("D:/tmp/test.txt",sep=",")
x.wide=reshape(x,direction="wide",
+ v.names=c("price"),
+ timevar="name",
+ idvar="time")
错误在`[.data.frame`(data, , timevar) : undefined columns selected
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.44.214.90
※ 编辑: goodparent1 来自: 114.44.214.90 (10/28 23:23)
1F:→ celestialgod:我用你的例子 是成功的... 10/28 23:55
2F:→ Wush978:请问你的原始档案的分隔符号是","吗? 10/29 00:11
3F:→ goodparent1:原始档分隔符号是空白。 10/29 01:35
4F:→ goodparent1:但是我sep用预设 会读不进档案。 10/29 01:44
5F:→ goodparent1:可能是因为我name,有些变数没有名称。 10/29 01:48
6F:→ goodparent1:可是na="NA",一样读不进档案。 10/29 01:50
7F:→ celestialgod:你可以先用EXCEL读进去 另存成csc 会比较好读进去R 10/29 02:27
8F:→ celestialgod: v 10/29 02:27
9F:→ goodparent1:我的资料有三百多万列,EXCEL放不下。 10/29 06:38
10F:→ ccwang002:我的经验,如果是三百多万列,一次转 R 也不一定成功 10/29 10:04
11F:→ goodparent1:那请问我该如何把负数转换成正数 10/29 22:50
12F:→ celestialgod:三百多万列,R要算上数小时... 10/29 23:54
13F:→ celestialgod:正数只要用abs取正值就好 10/29 23:54
14F:→ celestialgod:你可以试试看用matlab转... 10/29 23:55
15F:→ celestialgod:我把matlab code附於下篇文章 10/30 00:44
16F:→ celestialgod:另外,R也有unstack的function,你可以试试看!! 10/30 00:49
17F:→ celestialgod:unstack只能用在两行的data frame,抱歉 10/30 13:33