';数据';必须是向量类型,was';空';R
数据帧 这是aggData数据帧';数据';必须是向量类型,was';空';R,r,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
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)
从我所有的谷歌搜索中,它就像我的数据框中有空值一样
我的最终目标是在aggData数据帧中的数据条形图顶部绘制一条移动平均线。您应该使用
聚合(timeappeased~week+month,clean,FUN=mean)
而不是聚合(clean$timeappeased~week+month,clean,FUN=mean)
@lmo为什么在某些情况下需要指定数据帧,而不是其他人?e、 g.clean$timeappeased或just TimeElapsed一些函数,如aggregate
、lm
、glm
、和restrape
都有一个数据参数,您可以在其中提供data.frame的名称(有时矩阵可以工作)。如果数据参数提供了data.frame,则不必在变量前面提供df$。在函数中使用和中的时,也可以避免使用df$。您应该使用聚合(timepassed~week+month,clean,FUN=mean)
而不是聚合(clean$timepassed~week+month,clean,FUN=mean)
@lmo为什么在某些情况下需要指定数据帧,而不是其他人?e、 g.clean$timeappeased或just TimeElapsed一些函数,如aggregate
、lm
、glm
、和restrape
都有一个数据参数,您可以在其中提供data.frame的名称(有时矩阵可以工作)。如果数据参数提供了data.frame,则不必在变量前面提供df$。在
和功能中使用时,也可以避免使用df$。
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