Dear the friends of R-Ecology:
     I am a beginner for R language, and I am excited that I have reshaped successfully the original dataset to the separated CSV files for each pixel under the kindly help from several friends in R_Ecology. 
   I have written a simple function: data_reshape to do the work just mentioned before, the codes is following: 
-------------------------------------
data_reshape<-function(x1,x2,x3,x4,x5,x6)
{
for(i in 1:nrow(x1[,1]))
{
data01<-matrix(x1[i,2:241],ncol=12,byrow=T)
data02<-matrix(x2[i,2:241],ncol=12,byrow=T)
data03<-matrix(x3[i,2:241],ncol=12,byrow=T)
data04<-matrix(x4[i,2:241],ncol=12,byrow=T)
data05<-matrix(x5[i,2:241],ncol=12,byrow=T)
data06<-matrix(x6[i,2:25],ncol=12,byrow=T)
data<-rbind(data01,data02,data03,data04,data05,data06)
colnames(data)<-c('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec')
rownames(data)<-1901:2002
name.clim<-c("cld","dtr","frs","pre","tmn","tmp","tmx","vap","wet")
cell.name<-paste("F:/02PhD-TreeRing/05CRU /R/data_E_AS/",x1[i,1],name.clim[?],".csv",sep="")
write.csv(data,file=cell.name)
}
}
data_reshape(cld1901_1920,cld1921_1940,cld1941_1960,cld1961_1980,cld1981_2000,cld2001_2002)
data_reshape(dtr1901_1920,dtr1921_1940,dtr1941_1960,dtr1961_1980,dtr1981_2000,dtr2001_2002)
data_reshape(frs1901_1920,frs1921_1940,frs1941_1960,frs1961_1980,frs1981_2000,frs2001_2002)
data_reshape(pre1901_1920,pre1921_1940,pre1941_1960,pre1961_1980,pre1981_2000,pre2001_2002)
data_reshape(tmn1901_1920,tmn1921_1940,tmn1941_1960,tmn1961_1980,tmn1981_2000,tmn2001_2002)
data_reshape(tmp1901_1920,tmp1921_1940,tmp1941_1960,tmp1961_1980,tmp1981_2000,tmp2001_2002)
data_reshape(tmx1901_1920,tmx1921_1940,tmx1941_1960,tmx1961_1980,tmx1981_2000,tmx2001_2002)
data_reshape(vap1901_1920,vap1921_1940,vap1941_1960,vap1961_1980,vap1981_2000,vap2001_2002)
data_reshape(wet1901_1920,wet1921_1940,wet1941_1960,wet1961_1980,wet1981_2000,wet2001_2002)
-----------------------------
 
The variables contained ‘1901_1920’, ‘1921_1940’, ‘1941_1960’, ‘1961_1980’ and ‘1981_2000’ are downloaded climate data(cld, dtr, frs, pre, tmn, tmp, tmx, vap, wet) from CRU TS 2.1 Global Climate dataset for East Asia from 1901-2000.
The first column of each variable is the special values for 6017 pixels of this CRU dataset (such as 51447, 51582, 51584, 51573 etc.), while the rows (2:241) of each variable are the monthly climate data for 20 years.   
 The codes will run function: data_reshape nine times, each run can result in 6017 CSV files for some climate variable (cld, dtr, frs, pre, tmn, tmp, tmx, vap, wet). I want to store all 9*6017 CSV files in the same folder (F:/02PhD-TreeRing/05CRU /R/data_E_AS/), but I have the problem to escape repeated names for the same pixels, such as 51447cld, 51447dtr, 51447frs, 51447pre, 51447tmn, 51447tmp, 51447tmx, 51447vap and 51447wet.
 
During each run of the function: data_reshape, I am wondering if there is some way to attach the label of that climate variable to pixels No. in the names of CSV files? 
Any help is strongly appreciated,
thank you in advance,
Merry Christmas to you! 
 
----------------------
Zongshan, Li 
2009-12-27Research Center for Eco-Environmental Sciences,Chinese Academy of Sciences
Shuangqing Road, Haidian street, Beijing, 100085
Tel: 86-10-13699145748
QQ: 1141958023

website: http://www.rcees.ac.cn/   


      
	[[alternative HTML version deleted]]

