99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁(yè)精彩閱讀R語(yǔ)言實(shí)現(xiàn)數(shù)據(jù)操作
R語(yǔ)言實(shí)現(xiàn)數(shù)據(jù)操作
2017-12-17
收藏

R語(yǔ)言實(shí)現(xiàn)數(shù)據(jù)操作

1.選擇與查看數(shù)據(jù)
#選定數(shù)據(jù)
>data(iris)
#查看數(shù)據(jù),按列展開,觀測(cè)數(shù)據(jù)類型  
>str(iris)
'data.frame':   150 obs. of  5 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...    
#按列展開,進(jìn)行數(shù)據(jù)統(tǒng)計(jì)觀測(cè)  
>summary(iris)  
  Sepal.Length    Sepal.Width   
 Min.   :4.300   Min.   :2.000  
 1st Qu.:5.100   1st Qu.:2.800  
 Median :5.800   Median :3.000  
 Mean   :5.843   Mean   :3.057  
 3rd Qu.:6.400   3rd Qu.:3.300  
 Max.   :7.900   Max.   :4.400  
  Petal.Length    Petal.Width   
 Min.   :1.000   Min.   :0.100  
 1st Qu.:1.600   1st Qu.:0.300  
 Median :4.350   Median :1.300  
 Mean   :3.758   Mean   :1.199  
 3rd Qu.:5.100   3rd Qu.:1.800  
 Max.   :6.900   Max.   :2.500  
       Species  
 setosa    :50  
 versicolor:50  
 virginica :50  

 #按行展開,查看前10行
 >head(iris,10)                 Sepal.Length Sepal.Width Petal.Length
1           5.1         3.5          1.4
2           4.9         3.0          1.4
3           4.7         3.2          1.3
4           4.6         3.1          1.5
5           5.0         3.6          1.4
6           5.4         3.9          1.7
7           4.6         3.4          1.4
8           5.0         3.4          1.5
9           4.4         2.9          1.4
10          4.9         3.1          1.5
   Petal.Width Species
1          0.2  setosa
2          0.2  setosa
3          0.2  setosa
4          0.2  setosa
5          0.2  setosa
6          0.4  setosa
7          0.3  setosa
8          0.2  setosa
9          0.2  setosa
10         0.1  setosa   
#按行展開,觀測(cè)后10行  
>tail(iris,10)    
    Sepal.Length Sepal.Width Petal.Length
141          6.7         3.1          5.6
142          6.9         3.1          5.1
143          5.8         2.7          5.1
144          6.8         3.2          5.9
145          6.7         3.3          5.7
146          6.7         3.0          5.2
147          6.3         2.5          5.0
148          6.5         3.0          5.2
149          6.2         3.4          5.4
150          5.9         3.0          5.1
    Petal.Width   Species
141         2.4 virginica
142         2.3 virginica
143         1.9 virginica
144         2.3 virginica
145         2.5 virginica
146         2.3 virginica
147         1.9 virginica
148         2.0 virginica
149         2.3 virginica
150         1.8 virginica
#觀測(cè)數(shù)據(jù)內(nèi)的某一行                `
>table(iris$Sepal.Length)
4.3 4.4 4.5 4.6 4.7 4.8 4.9   5 5.1 5.2
  1   3   1   4   2   5   6  10   9   4
5.3 5.4 5.5 5.6 5.7 5.8 5.9   6 6.1 6.2
  1   6   7   6   8   7   3   6   6   4
6.3 6.4 6.5 6.6 6.7 6.8 6.9   7 7.1 7.2
  9   7   5   2   8   3   4   1   1   3
7.3 7.4 7.6 7.7 7.9
  1   1   1   4   1
#觀測(cè)數(shù)據(jù)的容量   
> object.size(iris)
7088 bytes                                 

深入觀測(cè)方法

#選擇某一行某一列數(shù)據(jù),一行一列   
>iris[1,1]  
[1] 5.1    
#使用c()選擇多行   
> sepal.iris = iris[,c("Sepal.Length","Sepal.Width")]
> str(sepal.iris)
'data.frame':   150 obs. of  2 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#指定觀測(cè)那幾行的那幾個(gè)
> FIVE.sepal.iris = iris[1:5,c("Sepal.Length","Sepal.Width")]
> str(FIVE.sepal.iris)
'data.frame':   5 obs. of  2 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6
#設(shè)置篩選條件,例如iris中species的僅包括setosa類型的數(shù)據(jù),后面指定了列數(shù)
> setosa.data = iris[iris$Species=="setosa",1:5]
> str(setosa.data)
'data.frame':   50 obs. of  5 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
#使用subset函數(shù)來(lái)獲取數(shù)據(jù)集的子集
> sepal.data = subset(iris,select = c("Sepal.Length","Sepal.Width"))
> str(sepal.data)
'data.frame':   150 obs. of  2 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#subset獲取僅包含setosa的數(shù)據(jù)
> setosa.data = subset(iris,Species=="setosa")
> str(setosa.data)
'data.frame':   50 obs. of  5 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
#subset運(yùn)用條件來(lái)篩選數(shù)據(jù)  
> example.data = subset(iris,Petal.Length<=1.4 & Petal.Width>=0.2,select = Species )
> str(example.data)
'data.frame':   21 obs. of  1 variable:
 $ Species: Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
#具有相同行相同列的數(shù)據(jù)合并為一組,
> flower.type = data.frame(Species = "setosa",Flower = "iris")
> merge(flower.type,iris[1:3,],by = "Species")
  Species Flower Sepal.Length Sepal.Width Petal.Length Petal.Width
1  setosa   iris          5.1         3.5          1.4         0.2
2  setosa   iris          4.9         3.0          1.4         0.2
3  setosa   iris          4.7         3.2          1.3         0.2
#函數(shù)order可以返回指定列進(jìn)行數(shù)據(jù)排序后的數(shù)據(jù)框,下面是花萼長(zhǎng)度從大到小排序
> head(iris[order(iris$Sepal.Length,decreasing = TRUE),])
    Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
132          7.9         3.8          6.4         2.0 virginica
118          7.7         3.8          6.7         2.2 virginica
119          7.7         2.6          6.9         2.3 virginica
123          7.7         2.8          6.7         2.0 virginica
136          7.7         3.0          6.1         2.3 virginica
106          7.6         3.0          6.6         2.1 virginica
擴(kuò)展
#函數(shù)sub與gsub支持使用正則表達(dá)示對(duì)字符串的處理,分別替換第一個(gè)字符與所有字符
> iris10 = iris
> sub("e","z",names(iris10))
[1] "Szpal.Length" "Szpal.Width"  "Pztal.Length" "Pztal.Width"  "Spzcies"     
> gsub("e","z",names(iris10))
[1] "Szpal.Lzngth" "Szpal.Width"  "Pztal.Lzngth" "Pztal.Width"  "Spzcizs"

數(shù)據(jù)分析咨詢請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說(shuō)明請(qǐng)參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }