2015年09月22日

时间:2022-01-20 14:04:13
#ABG,P80 TEM <- read.table(file = "Temperature.txt",header = T)> names(TEM) [1] "Sample"      "Date"        "DateNr"      "dDay1"       "dDay2"       [6] "dDay3"       "Station"     "Area"        "X31UE_ED50"  "X31UN_ED50" [11] "Year"        "Month"       "Season"      "Salinity"    "Temperature"[16] "CHLFa"      > str(TEM)'data.frame':8528 obs. of  16 variables: $ Sample     : Factor w/ 8528 levels "DANT.19900110",..: 1 2 3 4 5 6 7 8 9 10 ... $ Date       : int  19900110 19900206 19900308 19900404 19900509 19900620 19900718 19900815 19900919 19901017 ... $ DateNr     : Factor w/ 2343 levels "1/13/1992","1/13/1995",..: 408 437 445 428 448 1839 1956 2084 2262 133 ... $ dDay1      : int  7 34 64 91 126 168 196 224 259 287 ... $ dDay2      : int  9 36 66 93 128 170 198 226 261 289 ... $ dDay3      : int  9 36 66 93 128 170 198 226 261 289 ... $ Station    : Factor w/ 30 levels "DANT","DREI",..: 1 1 1 1 1 1 1 1 1 1 ... $ Area       : Factor w/ 10 levels "ED","GM","KZ",..: 10 10 10 10 10 10 10 10 10 10 ... $ X31UE_ED50 : num  681380 681380 681380 681380 681380 ... $ X31UN_ED50 : num  5920571 5920571 5920571 5920571 5920571 ... $ Year       : int  1990 1990 1990 1990 1990 1990 1990 1990 1990 1990 ... $ Month      : int  1 2 3 4 5 6 7 8 9 10 ... $ Season     : Factor w/ 4 levels "autumn","spring",..: 4 4 2 2 2 3 3 3 1 1 ... $ Salinity   : num  29.2 27.4 25 28.8 33.3 ... $ Temperature: num  4 6 7.3 8.2 17.4 18.1 17 21 15.1 13.8 ... $ CHLFa      : num  1.3 NA 21.1 25 10.2 6.2 7.9 7.85 13 11.8 ...> #先分别提取出1990-2005每一年的数据,eg:tem1990 <-TEM[TEM$Year==1990,]> #后再month来分temperature> tem1990 <-TEM[TEM$Year==1990,]> Month1990 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1991 <-TEM[TEM$Year==1991,]> Month1991 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1992 <-TEM[TEM$Year==1992,]> Month1992 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1993 <-TEM[TEM$Year==1993,]> Month1993 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1994 <-TEM[TEM$Year==1994,]> Month1994 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1995 <-TEM[TEM$Year==1995,]> Month1995 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1996 <-TEM[TEM$Year==1996,]> Month1996 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1997 <-TEM[TEM$Year==1997,]> Month1997 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1998 <-TEM[TEM$Year==1998,]> Month1998 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem1999 <-TEM[TEM$Year==1999,]> Month1999 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem2000 <-TEM[TEM$Year==2000,]> Month2000 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem2001 <-TEM[TEM$Year==2001,]> Month2001 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem2002<-TEM[TEM$Year==2002,]> Month2002 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem2003 <-TEM[TEM$Year==2003,]> Month2003 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem2004 <-TEM[TEM$Year==2004,]> Month2004 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> tem2005<-TEM[TEM$Year==2005,]> Month2005 <- tapply(TEM$Temperature,TEM$Month,FUN = mean,na.rm=T)> resultF <- data.frame(Month1990,Month1991,Month1992,Month1993,Month1994,Month1995,+       Month1996,Month1997,Month1998,Month1999,Month2000,Month2001,+       Month2002,Month2003,Month2004,Month2005)> resultF   Month1990 Month1991 Month1992 Month1993 Month1994 Month1995 Month1996 Month19971   5.174210  5.174210  5.174210  5.174210  5.174210  5.174210  5.174210  5.1742102   4.737400  4.737400  4.737400  4.737400  4.737400  4.737400  4.737400  4.7374003   6.125961  6.125961  6.125961  6.125961  6.125961  6.125961  6.125961  6.1259614   8.702035  8.702035  8.702035  8.702035  8.702035  8.702035  8.702035  8.7020355  12.293479 12.293479 12.293479 12.293479 12.293479 12.293479 12.293479 12.2934796  15.659933 15.659933 15.659933 15.659933 15.659933 15.659933 15.659933 15.6599337  18.077343 18.077343 18.077343 18.077343 18.077343 18.077343 18.077343 18.0773438  19.388355 19.388355 19.388355 19.388355 19.388355 19.388355 19.388355 19.3883559  16.995974 16.995974 16.995974 16.995974 16.995974 16.995974 16.995974 16.99597410 13.619670 13.619670 13.619670 13.619670 13.619670 13.619670 13.619670 13.61967011  9.848891  9.848891  9.848891  9.848891  9.848891  9.848891  9.848891  9.84889112  6.746339  6.746339  6.746339  6.746339  6.746339  6.746339  6.746339  6.746339   Month1998 Month1999 Month2000 Month2001 Month2002 Month2003 Month2004 Month20051   5.174210  5.174210  5.174210  5.174210  5.174210  5.174210  5.174210  5.1742102   4.737400  4.737400  4.737400  4.737400  4.737400  4.737400  4.737400  4.7374003   6.125961  6.125961  6.125961  6.125961  6.125961  6.125961  6.125961  6.1259614   8.702035  8.702035  8.702035  8.702035  8.702035  8.702035  8.702035  8.7020355  12.293479 12.293479 12.293479 12.293479 12.293479 12.293479 12.293479 12.2934796  15.659933 15.659933 15.659933 15.659933 15.659933 15.659933 15.659933 15.6599337  18.077343 18.077343 18.077343 18.077343 18.077343 18.077343 18.077343 18.0773438  19.388355 19.388355 19.388355 19.388355 19.388355 19.388355 19.388355 19.3883559  16.995974 16.995974 16.995974 16.995974 16.995974 16.995974 16.995974 16.99597410 13.619670 13.619670 13.619670 13.619670 13.619670 13.619670 13.619670 13.61967011  9.848891  9.848891  9.848891  9.848891  9.848891  9.848891  9.848891  9.84889112  6.746339  6.746339  6.746339  6.746339  6.746339  6.746339  6.746339  6.746339> resultFmean <- rowMeans(resultF)
#如何计算每一行的平均值和方差?均可用sapply | lapply 来做,#其中横向均值可用rowMeans 来做resultFmean <- rowMeans(resultF)rownames(resultF) <-c("1month","2month","3month","4month","5month",                      "6month","7month","8month","9month","10month",                      "11month","12month")sapply(resultF[1:12,],FUN = mean)

#计算结果很奇怪,都是一样的。。所以是否数据的问题,我个人认为方法没有问题