2013-07-30 62 views
2

我的帖子顯然不清楚,所以我試圖解決它,不要猶豫告訴我,如果我還不清楚!將朱利安日轉換爲R /日/月/年

我得到了一個物理變量的數據幀,每分鐘都有一個數據。我想在4分第一列轉換成一個單一的一個: 「%d /%M /%Y%H:%M」,在R.

Year Julian_day Hour Minute Air_temp Water_temp Rel_hum Wind_int Wind_dir 
2012 1 0 0 11.82 4.73 87.2 5.1 310 
2012 1 0 1 11.92 4.743 87.2 5 310 
2012 1 0 2 11.86 4.748 86.9 4.7 310 

(GMT)謝謝您的幫助!

+0

請提供一個[reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – Thomas

+0

也許苛刻要標記Q1新手? [可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)的要點是它闡明瞭你正在使用的對象類型。歡迎來到SO Doc。 – geotheory

+0

對不起,我修改了它,希望這個新的更清晰。 –

回答

6
# This imports your data into a variable named "weather" 
weather <- read.table(tc <- textConnection("Year Julian_day Hour Minute Air_temp Water_temp Rel_hum Wind_int Wind_dir 
2012 1 0 0 11.82 4.73 87.2 5.1 310 
2012 1 0 1 11.92 4.743 87.2 5 310 
2012 1 0 2 11.86 4.748 86.9 4.7 310"), header = TRUE); close(tc) 

# Combine the first four columns into a character vector 
date_info <- with(weather, paste(Year, Julian_day, Hour, Minute)) 
# Parse that character vector 
strptime(date_info, "%Y %j %H %M") 
+0

謝謝你的回覆和你的時間,但是我仍然有1個問題。我不明白textConnection的原理,我想知道是否解決我的問題是一個很好的解決方案,因爲我每年的每一分鐘都有一行,所以它是一個巨大的數據集。我想將4列到1個新列。 –

+1

(1)'textConnection'只是設置樣本數據的一種方式; (2)525600行不*那*不好。如果您確實需要節省空間,則可以在創建'date_info'後從數據框中刪除四列。嘗試一下,看看它是否工作... –

相關問題