r语言 ts函数 天tsdisplay是什么意思

关于R语言中的时间序列对象ts
ts {stats}
Description
The function ts is used to
create time-series objects. #函数ts用于创建时间序列对象
is.ts coerce an object to a time-series and test
whether an object is a time series.
#as.ts是将某个对象强制转换为时间序列;is.ts是判断对象是否为时间序列,如果是,则返回TRUE;否则FALSE
ts(data = NA, start = 1, end =
numeric(0), frequency = 1,
&& deltat = 1, ts.eps =
getOption("ts.eps"), class = , names = )
as.ts(x, ...)
a numeric vector or matrix of the observed
time-series values. A data frame will be coerced to a numeric
matrix via
data.matrix.&&
#data为观测时间序列值的数值向量或矩阵。数据框将通过data.matrix 强制转化为数值矩阵;
the time of the first observation. Either a single number or a
vector of two integers, which specify a natural time unit and a
(1-based) number of samples into the time unit. See the examples
for the use of the second form.&
#第一个观测值的时间。可以是单个数或两个整数组成的向量,分别指明自然时间单位和时间单位内的样本数;
&the time of the last observation, specified in
the same way as start. #最后观测值的时间。
frequency&
the number of observations per unit of time. #单位时间观测值的数目;
the fraction of the sampling
period between suc e.g., 1/12 for monthly
data. Only one of frequency or deltat
should be provided.
time series comparison tolerance.
Frequencies are considered equal if their absolute difference is
less than ts.eps.
class to be given to the result,
or none if NULL or "none". The default is
"ts" for a single series, c("mts", "ts")
for multiple series.
a character vector of names for
the series in a multiple series: defaults to the colnames of
data, or Series 1, Series 2,
an arbitrary R object.
arguments passed to methods
(unused for the default method).
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。trackbacks-2
转自该网站:
科学可视化中常用的一些颜色表:
Step-by-Step Procedure (to learn about "colors")
1.& The function call,&colors(), or with the British spelling,&colours(), returns a vector of& 657 color names in R.& The color names are in alphabetical order, except forcolors()[1], which is "white".& The names "gray" and "grey" can be spelled either way -- many shades of grey/gray are provided with both spellings.
2.& Particular color names of interest can be found if their positions in the vector are known, e.g.,
& colors()[c(552,254,26)][1] "red" "green" "blue"
3.&&grep&can be used to find color names of interest, e.g.,
& grep("red",colors())[1] 100 372 373 374 375 376 476 503 504 505 506 507 524 525 526 527 528 552 553[20] 554 555 556 641 642 643 644 645
& colors()[grep("red",colors())][1] "darkred" "indianred" "indianred1" "indianred2"&[5] "indianred3" "indianred4" "mediumvioletred" "orangered"&[9] "orangered1" "orangered2" "orangered3" "orangered4"&[13] "palevioletred" "palevioletred1" "palevioletred2" "palevioletred3"&[17] "palevioletred4" "red" "red1" "red2"&[21] "red3" "red4" "violetred" "violetred1"&[25] "violetred2" "violetred3" "violetred4"
& colors()[grep("sky",colors())][1] "deepskyblue" "deepskyblue1" "deepskyblue2" "deepskyblue3"&[5] "deepskyblue4" "lightskyblue" "lightskyblue1" "lightskyblue2"[9] "lightskyblue3" "lightskyblue4" "skyblue" "skyblue1"&[13] "skyblue2" "skyblue3" "skyblue4"
4.& The function&col2rgb&can be used to extract the RGB (red-green-blue) components of a color, e.g.,
& col2rgb("yellow")[,1]red 255green 255blue 0
Each of the three RGB color components ranges from 0 to 255, which is interpreted to be 0.0 to 1.0 in RGB colorspace.& With each of the RGB components having 256 possible discrete values, this results in 256*256*256 possible colors, or 16,777,216 colors.
While the RGB component values range from 0 to 255 in decimal, they range from hex 00 to hex FF.& Black, which is RGB = (0,0,0) can be represented in hex as #000000, and white, which is RGB = (255,255,255), can represented in hex as #FFFFFF.
5.& R provides a way to define an RGB triple with each of the color components ranging from 0.0 to 1.0 using the&rgb&function.& For example, yellow can be defined:
& rgb(1.0, 1.0, 0.0)[1] "#FFFF00"
The output is in hexadecimal ranging from 00 to FF (i.e., decimal 0 to 255) for each color component.& The 0.0 to 1.0 inputs are a bit odd, but are standard in RGB color theory.& Since decimal values from 0 to 255 are common, the&rgb&function allows a&maxColorValue&parameter as an alternative:
& rgb(255, 255, 0, maxColorValue=255)[1] "#FFFF00"
The R function,&, was written to display both hex and decimal values of the color components for a given color name:
GetColorHexAndDecimal &- function(color){& c &- col2rgb(color)& sprintf("#%02X%02X%02X %3d %3d %3d", c[1],c[2],c[3], c[1], c[2], c[3])}
& GetColorHexAndDecimal("yellow")[1] "#FFFF00 255 255 0"
This&GetColorHexAndDecimal&function will be used below in Step 9.
6.& Text of a certain color when viewed against certain backgrounds can be very hard to see, e.g., never use yellow text on a white background since there isn't good contrast between the two.& One simple hueristic in defining a text color for a given background color is to pick the one that is "farthest" away from "black" or "white".& One way to do this is to compute the color intensity, defined as the mean of the RGB triple, and pick "black" (intensity 0) for text color if the background intensity is greater than 127, or "white" (intensity 255) when the background intensity is less than or equal to 127.
The R function below,&SetTextContrastColor, gives a good text color for a given background color name:
SetTextContrastColor &- function(color){& ifelse( mean(col2rgb(color)) & 127, "black", "white")}
# Define this array of text contrast colors that correponds to each# member of the colors() array.TextContrastColor &- unlist( lapply(colors(), SetTextContrastColor) )
& SetTextContrastColor("white")[1] "black"& SetTextContrastColor("black")[1] "white"& SetTextContrastColor("red")[1] "white"& SetTextContrastColor("yellow")&[1] "black"
7.& The following R code produces the "R Colors" graphic shown at the top of this page (using&TextContrastColor&defined above):
# 1a. Plot matrix of R colors, in index order, 25 per row.# This example plots each row of rectangles one at a time.colCount &- 25 # number per rowrowCount &- 27
plot( c(1,colCount), c(0,rowCount), type="n", ylab="", xlab="",& axes=FALSE, ylim=c(rowCount,0))title("R colors")
for (j in 0:(rowCount-1)){& base &- j*colCount& remaining &- length(colors()) - base& RowSize &- ifelse(remaining & colCount, remaining, colCount)& rect((1:RowSize)-0.5,j-0.5, (1:RowSize)+0.5,j+0.5,&&& border="black",&&& col=colors()[base + (1:RowSize)])& text((1:RowSize), j, paste(base + (1:RowSize)), cex=0.7,&&& col=TextContrastColor[base + (1:RowSize)])}
8. Alphabetical order is not necessarily a good way to find similar colors.& The RGB values of each of the colors() was converted to hue-saturation-value (HSV) and then sorted by HSV.& This approach groups colors of the same "hue" together a bit better.& Here's the code and graphic produced:
# 1b. Plot matrix of R colors, in "hue" order, 25 per row.# This example plots each rectangle one at a time.RGBColors &- col2rgb(colors()[1:length(colors())])HSVColors &- rgb2hsv( RGBColors[1,], RGBColors[2,], RGBColors[3,],&&&& &&&&&&& maxColorValue=255)HueOrder &- order( HSVColors[1,], HSVColors[2,], HSVColors[3,] )
plot(0, type="n", ylab="", xlab="",axes=FALSE, ylim=c(rowCount,0), xlim=c(1,colCount))
title("R colors -- Sorted by Hue, Saturation, Value")
for (j in 0:(rowCount-1)){& for (i in 1:colCount)& {&& k &- j*colCount + i&& if (k &= length(colors()))&& {&&& rect(i-0.5,j-0.5, i+0.5,j+0.5, border="black", col=colors()[ HueOrder[k] ])&&& text(i,j, paste(HueOrder[k]), cex=0.7, col=TextContrastColor[ HueOrder[k] ])&& }& }}
9.& While the color matrices above are useful, a more useful display would include a rectangular area showing the color, the color index, the color name, and the RGB values, both in hexadecimal, which is often used in web pages.
The code for this is a bit tedious -- see Item #2 in the&&for complete details. Here is the first page of the&Chart of R colors.
10.& To create a PDF file (named ColorChart.pdf) with all the graphics shown on this page, issue this R command:
source("")
阅读(...) 评论()苹果/安卓/wp
苹果/安卓/wp
积分 198, 距离下一级还需 62 积分
权限: 自定义头衔
道具: 彩虹炫, 雷达卡, 热点灯, 雷鸣之声, 涂鸦板, 金钱卡, 显身卡, 匿名卡下一级可获得
权限: 签名中使用图片
购买后可立即获得
权限: 隐身
道具: 金钱卡, 雷鸣之声, 彩虹炫, 雷达卡, 涂鸦板, 热点灯
时间序列能否用ts函数表示日期,但是不用生成数据框呢??以便于进一步处理。
支持楼主:、
购买后,论坛将把您花费的资金全部奖励给楼主,以表示您对TA发好贴的支持
载入中......
Applied Econometrics with R page 152
太极无极 发表于
Applied Econometrics with R page 152没有吧,计量经济学,我说的是时间序列啊
Applied econometrics with R page 151 chapter 6 Time Series
太极无极 发表于
Applied econometrics with R page 151 chapter 6 Time Series恩 看到了, 但是书上只是年或者年月,不是年月日的格式,是不一样的
Applied econometrics with R 153&&and manual of zoo package
太极无极 发表于
Applied econometrics with R 153&&and manual of zoo package谢谢,我知道可以用zoo,但是我问的是用ts函数表示,因为做预测的时候zoo格式是用不了的。
ts 函数只能生成年度,季度和月度数据。估计你得另想办法了
论坛好贴推荐
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
为做大做强论坛,本站接受风险投资商咨询,请联系(010-)
邮箱:service@pinggu.org
合作咨询电话:(010)
广告合作电话:(刘老师)
投诉电话:(010)
不良信息处理电话:(010)
京ICP证090565号
京公网安备号
论坛法律顾问:王进律师

我要回帖

更多关于 r语言 ts frequency 的文章

 

随机推荐