Reputation: 221
I have data structured 4464 in rows, and 1 column. Data should be in 4464 in rows and 8 columns.
Data contains: Each file has a two line header, followed by data.The columns are: julian day, ten minute interval marker, temperature, pressure, wind speed, and wind direction. The ten minute interval marker is a number between 1 and 144 representing time. data comes from here
There are total of 12 data files like this, and my goal is put them in one 3D array. But I am stuck to fix this data form.
Example of Data
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
I tried and researched few things, but I don't know what the best way is.
My code was (Could not code with 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"))
I looked at other questions, and guide and data.frame seems like the best way, but I could not code. (Ended up with data dimension NULL.)
Please give me advice on this. Thank you.
Upvotes: 0
Views: 104
Reputation: 44555
Your problem seems to be using read.csv
instead of read.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")
Result:
> 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
Upvotes: 1