'数据'必须是矢量类型,是' NULL' [R

时间:2016-06-21 19:04:44

标签: r

数据框

这是aggData数据框。

 week   month   clean$TimeElapsed
1   7   2   233.3788428
2   8   2   197.321859
3   9   2   262.9656766
4   9   3   228.9536539
5   10  3   231.9331015
6   11  3   297.7748849
7   12  3   276.6380882
8   13  3   291.0149907
9   13  4   255.198273
10  14  4   344.8059474
11  15  4   278.0266588
12  16  4   285.8060417
13  17  4   319.1550685
14  18  5   266.6978501
15  19  5   257.9400897
16  20  5   230.6477697
17  21  5   214.5926981
18  22  5   215.9222798
19  22  6   209.9551517
20  23  6   252.4327421
21  24  6   271.0315055

代码

我正在使用TTR库,导入

install.packages("ggplot2")
install.packages("TTR")
install.packages("plotrix")

library(TTR)
library(ggplot2)
library(plotrix)

#import the data
## Create a directory to store the data
dirName <- "data"
dirPath <- "D/Developer Productivity"
dir <- file.path(dirPath, dirName)
dir.create(path = dir, showWarnings = TRUE, recursive = FALSE)

#read in the data
fileName <- "avgdata.csv"
file <- file.path(dir, fileName)
data <- read.csv(file)
clean <- data[c(1, 9)]

#add some date columns
clean$newDate <- strptime(as.character(clean$Date), "%m/%d/%Y")
clean$month <- strftime(clean$newDate, "%m")
clean$year <- strftime(clean$newDate, "%Y")
clean$week <- strftime(clean$newDate, "%U")

#aggregate data based on weekly averages
aggData <- aggregate(clean$TimeElapsed ~ week + month, clean, FUN = mean) 

#calculate the moving average
ema.20 <- SMA(aggData$TimeElapsed, 20) 
ema.2 <-SMA(aggData1$TimeElapsed, 2)

#create graph
barp(aggData$TimeElapsed, col = "grey70")
lines(ema.2)
points(ema.2)

问题

电子邮件行引发了以下错误:

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  : 'data' must be of a vector type, was 'NULL'

从我的所有谷歌搜索中,它的作用就像我的数据框中有空值

我的最终目标是在aggData数据框中的数据条形图上绘制移动平均线。

0 个答案:

没有答案