[問題] 如何在取data其中一部份算mean
[問題類型]:
[軟體熟悉度]:
新手(沒寫過程式,R 是我的第一次)
[問題敘述]:
我想把data的資料分段算出平均數,例如 gsprice 第1筆到第50筆算出1個平均數,
第51筆到第100筆再取一個平均數
[程式範例]:
rm(list=ls()) #清除所有內容
library(TSA);library(tseries);library(FinTS);library(fGarch);library(dynlm)
datain <- read.table("C:\\R\\mydata.txt",header=TRUE)#讀入文字檔資料
attach(datain)
lsprice <- log(sprice)
lfprice <- log(fprice)
gsprice <- diff(lsprice)*100
gfprice <- diff(lfprice)*100
obsno <<- length(date)
datam <<-
matrix(cbind(date[-1],lsprice[-1],lfprice[-1],NFPI[-1],gsprice,gfprice),obsno-1,6)
colnames(datam) <- c("date","lsprice","lfprice","NFPI","gsprice","gfprice")
obs <<- length(datam[,1]) # obs is the sample size
y <<- matrix(0,obs,1)
y[,1]<- datam[,5]
[環境敘述]: win10 3.2.3
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.218.199.237
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1457709472.A.814.html
→
03/11 23:59, , 1F
03/11 23:59, 1F
→
03/12 00:17, , 2F
03/12 00:17, 2F
→
03/12 00:18, , 3F
03/12 00:18, 3F
→
03/12 00:53, , 4F
03/12 00:53, 4F
→
03/12 11:22, , 5F
03/12 11:22, 5F
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章
14
26