2014-02-18 53 views
0

我有数据结构4464行和1列。 数据应该在4464行和8列中。如何分隔R中的数据列

数据包含: 每个文件都有一个两线 头,后跟data.The列有:儒略日,10分钟 间隔标记,温度,压力,风速和风向。十分钟间隔标记是代表时间的1和144之间的数字。 数据来自here

总共有12个这样的数据文件,我的目标是把它们放在一个3D数组中。 但我坚持要修复此数据表单。数据

Jan 13 Station : 8900 Harry    
    Lat : 83.00S Long : 121.40W Elev : 957 M 
    1 1 -7.8 879.0 5.6 360.0 444.0 9.1 
    1 2 -7.9 879.1 4.6 360.0 444.0 9.1 
    1 3 -7.6 879.2 4.1 345.0 444.0 9.1 
    1 4 -7.6 879.3 4.1 339.0 444.0 9.1 
    1 5 -7.6 879.4 4.8 340.0 444.0 9.1 
    1 6 -7.9 879.4 3.6 340.0 444.0 9.1 
    1 7 -8.0 879.3 4.6 340.0 444.0 9.1 
    1 8 -8.0 879.4 4.1 340.0 444.0 9.1 
    1 9 -8.2 879.4 5.8 338.0 444.0 9.1 
    1 10 -8.4 879.5 4.6 339.0 444.0 9.1 

例子我试图和研究一些东西,但我不知道最好的方法是什么。

我的代码是(无法与data.frame代码...):

setwd("/Users/Gizmo/Documents/Henry") 
    dir() 
    h13<-dir() 
    henry<-read.csv(h13[1],skip=2,header=FALSE) 
    colnames(c("J-Day","MinInter","Temp","Pressure","WindSpeed","WindDir","Ext1","Ext2")) 

我看了看其他的问题,引导和data.frame似乎是最好的方式,但我不能代码。 (结束与数据维NULL。)

请给我这方面的意见。谢谢。

+0

是不是正是你的数据文件看起来像?如果是这样,你需要'read.table',而不是'read.csv'。 – Thomas

+0

哦CSV是逗号分隔的不是它。谢谢! – user3325640

回答

1

你的问题好像是用的,而不是read.csvread.table

henry <- read.table(text='Jan 13 Station : 8900 Harry    
    Lat : 83.00S Long : 121.40W Elev : 957 M 
    1 1 -7.8 879.0 5.6 360.0 444.0 9.1 
    1 2 -7.9 879.1 4.6 360.0 444.0 9.1 
    1 3 -7.6 879.2 4.1 345.0 444.0 9.1 
    1 4 -7.6 879.3 4.1 339.0 444.0 9.1 
    1 5 -7.6 879.4 4.8 340.0 444.0 9.1 
    1 6 -7.9 879.4 3.6 340.0 444.0 9.1 
    1 7 -8.0 879.3 4.6 340.0 444.0 9.1 
    1 8 -8.0 879.4 4.1 340.0 444.0 9.1 
    1 9 -8.2 879.4 5.8 338.0 444.0 9.1 
    1 10 -8.4 879.5 4.6 339.0 444.0 9.1', header=FALSE, skip=2) 
names(henry) <- c("J-Day","MinInter","Temp","Pressure","WindSpeed","WindDir","Ext1","Ext2") 

结果:

> henry 
    J-Day MinInter Temp Pressure WindSpeed WindDir Ext1 Ext2 
1  1  1 -7.8 879.0  5.6  360 444 9.1 
2  1  2 -7.9 879.1  4.6  360 444 9.1 
3  1  3 -7.6 879.2  4.1  345 444 9.1 
4  1  4 -7.6 879.3  4.1  339 444 9.1 
5  1  5 -7.6 879.4  4.8  340 444 9.1 
6  1  6 -7.9 879.4  3.6  340 444 9.1 
7  1  7 -8.0 879.3  4.6  340 444 9.1 
8  1  8 -8.0 879.4  4.1  340 444 9.1 
9  1  9 -8.2 879.4  5.8  338 444 9.1 
10  1  10 -8.4 879.5  4.6  339 444 9.1 

> str(henry) 
'data.frame': 10 obs. of 8 variables: 
$ J-Day : int 1 1 1 1 1 1 1 1 1 1 
$ MinInter : int 1 2 3 4 5 6 7 8 9 10 
$ Temp  : num -7.8 -7.9 -7.6 -7.6 -7.6 -7.9 -8 -8 -8.2 -8.4 
$ Pressure : num 879 879 879 879 879 ... 
$ WindSpeed: num 5.6 4.6 4.1 4.1 4.8 3.6 4.6 4.1 5.8 4.6 
$ WindDir : num 360 360 345 339 340 340 340 340 338 339 
$ Ext1  : num 444 444 444 444 444 444 444 444 444 444 
$ Ext2  : num 9.1 9.1 9.1 9.1 9.1 9.1 9.1 9.1 9.1 9.1 
+0

非常感谢! – user3325640

相关问题