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

熱線電話:13121318867

登錄
首頁精彩閱讀R語言做數(shù)據(jù)分析(8)_數(shù)據(jù)的輸入與輸出之READ函數(shù)_數(shù)據(jù)分析師
R語言做數(shù)據(jù)分析(8)_數(shù)據(jù)的輸入與輸出之READ函數(shù)_數(shù)據(jù)分析師
2014-12-06
收藏

R語言做數(shù)據(jù)分析(8)_數(shù)據(jù)的輸入與輸出之READ函數(shù)_數(shù)據(jù)分析師

read.table() 函數(shù)
1、用于讀入表格(表)類型的數(shù)據(jù),同時(shí)生成數(shù)據(jù)框?qū)ο蟆?/span>
2、讀入的數(shù)據(jù)要求有規(guī)則的分隔符,默認(rèn)有:空格、TAB、換行符、回車符;其它的分隔符,通過sep=來進(jìn)行指定。

read.table(file, header = FALSE, sep = "", quote = "\"'",
           dec = ".", row.names, col.names,
           as.is = !stringsAsFactors,
           na.strings = "NA", colClasses = NA, nrows = -1,
           skip = 0, check.names = TRUE, fill = !blank.lines.skip,
           strip.white = FALSE, blank.lines.skip = TRUE,
           comment.char = "#",
           allowEscapes = FALSE, flush = FALSE,
           stringsAsFactors = default.stringsAsFactors(),
           fileEncoding = "", encoding = "unknown")

  1. file:指定讀入的文件,或者文件所在地址;
  2. header:是否讀入列名,默認(rèn)是不讀入;
  3. sep:來進(jìn)行指定分隔符:讀入的數(shù)據(jù)要求有規(guī)則的分隔符,可以是:空格、TAB、換行符、回車符;
  4. as.is:讀入的字符是否轉(zhuǎn)換成因子,默認(rèn)所有讀入的字符都轉(zhuǎn)換成因子;
  5. colClasses:指定列的數(shù)據(jù)類型格式
  6. header=TRUE 第一行是否是列的名稱,默認(rèn)是TRUE
  7. stringsAsFactors= 是否字符轉(zhuǎn)化成因子,默認(rèn)是true
  8. row.names=c()指定各行的名稱
  9. col.names=C()指定列的名稱,如果讀入是文件沒有頭,可以指定
  10. skip=N 從文件第幾行開始讀入數(shù)據(jù)
  11. nrows=N 讀入的最大行數(shù)
  12. na.strings=c()指定什么樣的字符表示值缺少
  13. comment.char=‘’ 指定評(píng)論的開始字符,默認(rèn)是#
  14. dec= 指定小數(shù)點(diǎn)數(shù)
  15. encoding=指定非non-ASCII的編碼規(guī)則

例如:
demo_3<-read.table('e:/demo_3.txt',header=T)
<a href='/map/r/' style='color:#000;font-size:inherit;'>R語言</a>讀取數(shù)據(jù)
 
read.fwf()函數(shù)
1、適用用于讀入數(shù)據(jù)相應(yīng)沒有相應(yīng)的分隔符,但是讀入的數(shù)據(jù)字段長(zhǎng)度是固定長(zhǎng)度。
2、數(shù)據(jù)導(dǎo)入R后,生成列表對(duì)象。
讀入固定分隔長(zhǎng)度的數(shù)據(jù);

read.fwf(file, widths, header = FALSE, sep = "\t",
         skip = 0, row.names, col.names, n = -1,
         buffersize = 2000)

  1. file:指定讀入的文件,或者文件所在地址;
  2. widths:指定分隔的長(zhǎng)度,可以等于向量指定不同的分隔;
  3. buffersize:一次最大的讀入行數(shù);
  4. n:讀入數(shù)據(jù)的行數(shù),默認(rèn)為無數(shù);

例如:在這個(gè)數(shù)據(jù)中,前面的3個(gè)字符與接下來的3個(gè)數(shù)字表示名稱、得分,因?yàn)槎€(gè)字段之間沒有分隔符號(hào),但其長(zhǎng)度是固定的,所以適合用本函數(shù)。
ABC123%$12
TEX124@#12
y o14 @@#
read.fwf('e:/demo_1.txt',widths=c(3,3),col.names=c('name','score'));
<a href='/map/r/' style='color:#000;font-size:inherit;'>R語言</a>讀取數(shù)據(jù)
w <- readline()函數(shù)
1、用于程序的交互,根據(jù)輸入的條件來判斷下一步執(zhí)行的方向;
2、通過鍵盤讀入一行數(shù)據(jù);
例如:根據(jù)輸入的來判斷后續(xù)程序的執(zhí)行流程

Demo_2<-function()
{
         input<-readline("DO you think R is hard to learn,Please give your choice:Y or N ")
         if(input=="Y")
                   cat("Come on; Spent more time.\n")
         else
                   cat("Good!")
}
 

Demo_2()

<a href='/map/r/' style='color:#000;font-size:inherit;'>R語言</a>讀取數(shù)據(jù)
Readlines() 函數(shù)
1、控制讀入的數(shù)據(jù)行數(shù),非批處理,有點(diǎn)類似于數(shù)據(jù)庫中的指標(biāo)操作,可對(duì)文件中的數(shù)據(jù)逐行操作。2、這個(gè)對(duì)于讀入日志類的數(shù)據(jù)很有用。例如:通過對(duì)讀入數(shù)據(jù)的每行來判斷是否有需要的數(shù)據(jù),有再對(duì)數(shù)據(jù)進(jìn)行處理;tips:該數(shù)據(jù)配合R中的正則表達(dá)式相關(guān)函數(shù),對(duì)于處理不規(guī)則的數(shù)據(jù)很強(qiáng)大。
例如:
1、  與文件demo_1建立連接
con<- file("demo_3","r")
2、指定每次執(zhí)行只讀入一行;
RC<-readLines(con,n=1)
3、關(guān)閉聯(lián)接
close(con)
 <a href='/map/r/' style='color:#000;font-size:inherit;'>R語言</a>讀取數(shù)據(jù)
說明:
1、如果讀到文件的最后,則length(RC)=0;EOF文件最后返回的空值。
2、N控制每次讀入幾行;
3、當(dāng)讀到最后要重新開始的時(shí)間:seek(con=c,where=0),返回當(dāng)前指標(biāo)所有的位置

數(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ù)說明請(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); }