我发现处理此类问题的包装数据、表格和润滑油非常有用:
# libraries
library(data.table)
library(lubridate)
# Function that returns Root Mean Squared Error
# set the working directory
setwd("D:\\Results\\")
# Get the header 1st line of the data
header <-scan("4001968.txt", nlines=1, what =character())
#Define number of lines to skip, which is 2
y <- read.table("4001968.txt",skip=2,header=F,sep="\t")
# Add the character vector header on as the names component
names(y) <- header
#Function for calculating RMSE
rmse <- function(error)
{
sqrt(mean(error^2))
}
# Convert characater to numeric
y$cout <- as.numeric(as.character(y$cout))
y$rout <- as.numeric(as.character(y$rout))
y <- as.data.table(y)
# Calculate error
error <- y[month(DATE)==1, cout-rout]
# Invocation of functions
rmse(error)