我每天有最低温度,最高温度,最低露点和最高露点。此数据包含NaN,因此我想进行各种操作;
我的数据看起来像
Station Date Month Day Year MaxTemp MinTemp MaxDewPoint MinDewPoint
ORD 1/1/1948 1 1 1948 35.6 26.6 34.16 -27.4
ORD 1/2/1948 1 2 1948 -2 -16 -16.96 -27.04
ORD 1/3/1948 1 3 1948 -4 -26 -12 -26
ORD 1/4/1948 1 4 1948 -5 -26 -15 -26
ORD 1/5/1948 1 5 1948 8 -25 3 NaN
ORD 1/6/1948 1 6 1948 -11 -25 -24 -25
ORD 1/7/1948 1 7 1948 1 -23 NaN -23
ORD 1/8/1948 1 8 1948 1 -22 -9 NaN
ORD 1/9/1948 1 9 1948 NaN -22 -5 -22
ORD 1/10/1948 1 10 1948 10 NaN -2 -22
ORD 1/11/1948 1 11 1948 -11 -21 -23 -21
ORD 1/12/1948 1 12 1948 3 -12 -7.96 -20.92
ORD 1/13/1948 1 13 1948 6.98 -7.6 -7.6 -20.2
ORD 1/14/1948 1 14 1948 3.92 -9.4 -11.2 NaN
ORD 1/15/1948 1 15 1948 6 -7 -5.98 NaN
ORD 1/16/1948 1 16 1948 3 -11 -7.96 -20.02
到目前为止,我设法编写了几行代码,但是我不确定这是正确的代码还是最有效的代码。
install.packages("dplyr")
install.packages("stringr")
library(dplyr)
library(stringr)
#setting up workspace in the folder#
setwd("E:/Climate Data Analysis/Asignment 1")
#opening a CSV file in r program#
data<- read.csv("chiacagost.csv", header=TRUE, sep=",")
#making data frame of the variables#
dframe<- data.frame(data)
# Missing percentage of the data by column
MisMxTMP<-dframe%>%summarise(NAMisMxTMP=sum(is.na(Max.Temp)/length(Max.Temp)))*100
misMnTMP<-dframe%>%summarise(NAmisMnTMPL=sum(is.na(Min.Temp)/length(Min.Temp)))*100
MisMxDTMP<-dframe%>%summarise(NAMisMxDTMP=sum(is.na(Max.Dew.Point)/length(Max.Dew.Point)))*100
MisMnDTMP<-dframe%>%summarise(NAMisMnDTMP=sum(is.na(Min.Dew.Point)/length(Min.Dew.Point)))*100
#Calcualte Mean temperature and dew point
MeanTMP<-dframe%>% mutate(MeanTMP=rowMeans(cbind(dframe$Max.Temp,dframe$Min.Temp),na.rm=TRUE))
#Minimum Dew point had more than 12 percent of missing data but i could not locate which years so the code below doesnot exclude NA
MeanDTMP<-dframe%>% mutate(MeanDTMP=rowMeans(cbind(dframe$Max.Dew.Point,dframe$Min.Dew.Point),na.rm=TRUE))
从这个结果中,我打算分别获取所有4个变量(泰尔森和OLS)的年度趋势,并进行t检验。将所有结果包括在趋势图中。