官术网_书友最值得收藏!

Slicing and dicing datasets

Our first example is to pick all stocks listed on the NYSE by using an R dataset called marketCap.Rdata, shown in the code here:

> con<-url("http://canisius.edu/~yany/RData/marketCap.RData") 
> load(con) 
> head(.marketCap) 

The associated output is shown here:

> head(.marketCap) 
  Symbol                       Name MarketCap Exchange 
1      A Agilent Technologies, Inc. $12,852.3     NYSE 
2     AA                 Alcoa Inc. $28,234.5     NYSE 
3   AA-P                 Alcoa Inc.     $43.6     AMEX
4 AAC Ableauctions.Com Inc $4.3 AMEX 5 AAI AirTran Holdings, Inc. $156.9 NYSE 6 AAP Advance Auto Parts Inc $3,507.4 NYSE

We have various ways to choose a subset of the R dataset called .marketCap. Note that there is a dot in front of .marketCap:

a<-.marketCap[1]      # choose the 1st column  
b<-.marketCap$SYMBOL  # another way to choose the 1st column  
c<-.marketCap[,1:2]   # choose the first two columns  
d<-subset(.marketCap,.marketCap$EXCHANGE=="NYSE") 
e<-subset(head(.marketCap)) 
f<-subset(.marketCap,.marketCap$MARKET>200 & .marketCap$MARKETCAP<=3000) 

A Python dataset is downloadable at http://canisius.edu/~yany/python/marketCap.pkl.

主站蜘蛛池模板: 嵊州市| 南和县| 天峻县| 青岛市| 德兴市| 岳西县| 东乌珠穆沁旗| 安康市| 松潘县| 武陟县| 宁海县| 黄龙县| 汉寿县| 友谊县| 永靖县| 武定县| 临沭县| 伊通| 兖州市| 平凉市| 波密县| 重庆市| 利辛县| 南昌市| 石棉县| 康平县| 东山县| 普格县| 习水县| 伽师县| 华亭县| 盘山县| 嘉兴市| 凌海市| 二连浩特市| 西峡县| 安远县| 鸡西市| 东明县| 芦山县| 上思县|