<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sirawit Takeo on Medium]]></title>
        <description><![CDATA[Stories by Sirawit Takeo on Medium]]></description>
        <link>https://medium.com/@sirawittakeo?source=rss-1ab7fae7047b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0GWn5doBBfMJQC17.</url>
            <title>Stories by Sirawit Takeo on Medium</title>
            <link>https://medium.com/@sirawittakeo?source=rss-1ab7fae7047b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 07:55:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sirawittakeo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data Analysis with R #5]]></title>
            <link>https://medium.com/@sirawittakeo/data-analysis-with-r-3-1a4e6aa7c779?source=rss-1ab7fae7047b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a4e6aa7c779</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-mining]]></category>
            <dc:creator><![CDATA[Sirawit Takeo]]></dc:creator>
            <pubDate>Wed, 17 May 2017 15:05:22 GMT</pubDate>
            <atom:updated>2017-05-17T17:59:58.348Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>ลองมาดูการทำ Data Analysis กันสักหนึ่ง algorithm จากการทำ Data Mining ดูนะครับ</blockquote><p><em>ตอนแรกเราจะทำการอ่าน transactions ก่อนอ่านไฟล์ต้อง set working directory ปัจจุบันโดย setwd ก่อนครับ</em><br><em>ไฟล์ชื่อ Groceries_dataset.csv เขามาเป็น data set ที่จะมาทำ algorithm Apriori ครับ ไฟล์ csv นี้นำมาจาก <br></em><a href="https://raw.githubusercontent.com/nupur1492/RProjects/master/MarketBasketAnalysis/Groceries_dataset.csv">rawdata of Groceries_dataset.csv</a> เป็นข้อมูลของการซื้อของจากมินิมาร์ทหนึ่งๆในช่วงนึงในสินค้าที่พบบ่อยๆและมาเก็บเป็น data frame</p><p><em>หลังจากนั้นทำการ preprocessing โดยการ sort ข้อมูลจาก Member_number ครับ</em></p><pre>#read transactions<br>setwd(“E:/downloads”)<br>df_groceries &lt;- read.csv(“Groceries_dataset.csv”)<br>str(df_groceries)<br>df_sorted &lt;- df_groceries[order(df_groceries$Member_number),]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*UbA_12ywSJQma3wQ_29HWw.png" /><figcaption>ข้อมูลโครงสร้าง data frame จากการ run &gt;str(df_groceries)</figcaption></figure><p><em>ข้อมูลเลขตรง column Member_number จะนำมาคำนวณได้ตรงเปลี่ยน class ให้เป็น numeric ก่อนครับ</em></p><pre>#convert member number to numeric<br>df_sorted$Member_number &lt;- as.numeric(df_sorted$Member_number)</pre><p><em>เปลี่ยนข้อมูลการซื้อให้เป็นฟอร์แมตทีเช็คตัวซ้ำได้โดยเปลี่ยนเป็น class factor ก็จะนำมาใช้ได้เลย</em></p><pre>#convert item description to categorical format<br>df_sorted$itemDescription &lt;- as.factor(df_sorted$itemDescription)<br>str(df_sorted)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*J1-W3AZj0NVJaVMXZO05lw.png" /><figcaption>ข้อมูลโครงสร้าง data frame จากการ run &gt;str(df_sorted)</figcaption></figure><p><em>ทำการเปลี่ยน data frame เป็นฟอร์แมต transaction เพื่อจะทำฟังก์ชัน Apriori<br>อย่าลืม include package plyr เพื่อใช้ฟังก์ชัน dplyr</em></p><pre>#convert dataframe to transaction format using ddply;<br>library(&quot;plyr&quot;)<br>if(sessionInfo()[‘basePkgs’]==”dplyr” | sessionInfo()[‘otherPkgs’]==”dplyr”){<br> detach(package:dplyr, unload=TRUE)<br>}</pre><p><em>รวมทุกข้อมูลที่ซื้อมาให้ group โดย customer โดยใช้ฟังก์ชัน ddply(จาก package plyr)<br>หลังจากนั้นลบ column Member_number กับ Date ออก เพราะข้อมูลถูก group แล้วเราจะใช้แค่ item และตั้งชื่อ comlumn ว่า itemList เพื่อให้ data frame สำเร็จรูปที่สุด</em></p><pre>#group all the items that were bought together; by the same customer on the same date<br>df_itemList &lt;- ddply(df_groceries, c(“Member_number”,”Date”), function(df1)paste(df1$itemDescription,collapse = “,”))</pre><pre>#remove member number and date<br>df_itemList$Member_number &lt;- NULL<br>df_itemList$Date &lt;- NULL<br>colnames(df_itemList) &lt;- c(&quot;itemList&quot;)</pre><p><em>เขียนไฟล์ csv ที่ preprocessing เสร็จแล้วลง csv ใหม่ โดยมีชื่อแถวอยู่และไม่มี logical value อยู่</em></p><pre>#write to csv format<br>write.csv(df_itemList,”ItemList.csv”, quote = FALSE, row.names = TRUE)</pre><p><em>include package arules เพื่อที่จะใช้ฟังก์ชัน apriori<br>หลังจากนั้นดึงข้อมูลที่เขียนไว้ก่อนหน้านี้มาใช้ โดยที่ไม่ลบตัวซ้ำ ฟอร์มอตแบบ basket</em></p><pre>library(arules)</pre><pre>#convert csv file to basket format<br>txn = read.transactions(file=”ItemList.csv”, rm.duplicates= FALSE, format=”basket”,sep=”,”,cols=1);</pre><p><em>ลบ quote เครื่องหมายที่ยังมีอยู่ออก โดยฟังก์ชัน gsub</em></p><pre>#remove quotes from transactions<br>txn@itemInfo$labels &lt;- gsub(“\””,””,txn@itemInfo$labels)</pre><p><em>มาถึงขั้นตอนเข้า algorithm apriori ต้องทำการทดสอบ sup กับ conf ก่อนว่าค่า max (ลองเช็คค่าจาก output) ของมันอยู่ตรงไหนละค่อยๆกำหนดค่าที่เหมาะสมที่เราอยากได้ ผมใช้ min lenght = 3 (3 items ที่สัมพันธ์กันขึ้นไป) / sup = 0.001 / conf = 0.1</em></p><pre>#run apriori algorithm<br>basket_rules &lt;- apriori(txn,parameter = list(minlen=3,sup = 0.001, conf = 0.1, target=”rules”))</pre><p><em>ดู output จากการทำ apriori โดยจะเลือกดูแค่ที่มีค่าเยอะๆทางหัว 20 ค่า เซ็จได้จากค่า head</em></p><pre>#view rules<br>inspect(head(basket_rules,20))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*HzFL-AYnOfcjufQ2G3oQkQ.png" /><figcaption>output ที่ผ่าน sup และ conf นั้นๆได้ output ออกมา 17 ตัว</figcaption></figure><p><em>ลองเปลี่ยน min length = 4 (4 items ที่สัมพันธ์กันขึ้นไป) / sup = 0.0001 / conf = 0.1 ได้ output ดังนี้</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*HdqGrmDx5Inf9gLbxmNWKA.png" /></figure><blockquote>เราจะเห็นได้ถึงความสัมพันธ์ที่เกิดขึ้นได้ชัดเจนเลยว่าเป็นอย่างไร และมีค่า lift บอกมาให้ด้วยถึงความขึ้นอยู่ต่อกันของ lhs กับ rhs</blockquote><blockquote>ที่เด่นๆเลยจากค่า head อันที่ 1<br>- ผลลัพธ์ของ output แรก (3 items) ผู้คนซื้อ { sausage และ yogurt } ก็จะซื้อ { whole milk } ตามเป็นส่วนใหญ่ <br>- ส่วน output ที่สอง (4 items) ผู้คนซื้อ { prosecco, sausage และ waffles} ก็จะซื้อ { other vegetables } ตามเป็นส่วนใหญ่</blockquote><p><strong><em>*เพิ่มเติม*</em></strong><em><br>ลอง plot ดูความถี่ของการซื้อคนส่วนใหญ่ดูเล่นๆครับว่าอะไรที่คนซื้อกันเยอะที่สุด ของที่ผู้คนซื้อๆเยอะไม่จำเป็นต้องมีความสัมพันธ์กับข้องชิ้นอื่นก็ได้ครับ แค่เพียงแต่มีโอกาสเพิ่มความสัมพันธ์มากขึ้น</em></p><pre>itemFrequencyPlot(txn, topN = 7)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*XpWRBw8VIg1FBYxdTantBg.png" /></figure><blockquote>เห็นไหมครับการวิเคราะห์ข้อมูลไม่ยากอย่างที่คิดเพียงศึกษาเพิ่มเติมเล็กน้อยก็สามารถทำได้กับข้อมูลชุดอื่นๆได้อีกมากมายจำนวนมาก :D</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a4e6aa7c779" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Analysis with R #4]]></title>
            <link>https://medium.com/@sirawittakeo/data-analysis-with-r-3-b2f481d12880?source=rss-1ab7fae7047b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2f481d12880</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Sirawit Takeo]]></dc:creator>
            <pubDate>Wed, 26 Apr 2017 06:00:40 GMT</pubDate>
            <atom:updated>2018-12-14T06:37:13.882Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>มาถึงการวิเคราะห์ข้อมูลแล้วครับ</blockquote><blockquote>เราจะมาดูการวิเคราะห์ข้อมูลอย่างง่ายกันนะครับ นำ data set มาจาก <a href="https://www.kaggle.com/datasets">https://www.kaggle.com/datasets</a> โดยเลือก data set <br>“ IMDB 5000 Movie Dataset” ซึ่งมีข้อมูลที่น่าสนใจอยู่พอดีโดยจะลองทำ Visualiztion นักแสดงนำและผู้กำกับที่สามารถทำหนังได้ rating สุดสุดโดยเฉลี่ย</blockquote><p><em>เพิ่ม library ที่จะใช้ฟังก์ชันต่างๆ เพื่อมา plot และอ่านไฟล์.csv หลังจากนั้น เซ็ต directory ที่เราจะดึงไฟล์มาอ่านและดึงข้อมูลมาเก็บไว้เป็น data frame</em></p><pre>library(ggplot2) # เพิ่ม Data visualization<br>library(readr) # เพิ่ม read_csv function</pre><pre>library(plyr)<br>library(ggthemes)<br>setwd(“E:/downloads”) # เซ็ต current directory ที่จะอ่านไฟล์<br>dat &lt;- read.csv(“movie_metadata.csv”, header=TRUE)<br>df &lt;- as.data.frame(dat)<br>head(df)</pre><p><em>คำนวณค่าเฉลี่ยและค่าเบี่ยงเบนมาตรฐานของนักแสดงนำ (actor) เพื่อจะนำไป plot และ </em>preprocess ตัวที่มี rating ไม่ผ่านเกณฑ์ขั้นต่ำที่จะนำมา plot</p><pre>ratingdat &lt;- ddply(df, c(“actor_1_name”), summarise,<br> M = mean(imdb_score, na.rm=T),<br> SE = sd(imdb_score, na.rm=T)/sqrt(length(na.omit(imdb_score))),<br> N = length(na.omit(imdb_score)))<br>ratings&lt;-ratingdat[which(ratingdat$N&gt;=15),]</pre><p><em>นำข้อมูลนักแสดงนำเปลี่ยนเป็น factor (ข้อมูลที่ซ้ำจะถูก group ไว้เป็น factor) ที่จัดลำดับแล้วเรียงจากค่าเฉลี่ยของ rating และ plot</em></p><pre>ratings$actor_1_name &lt;- factor(ratings$actor_1_name)<br>ratings$actor_1_name &lt;- reorder(ratings$actor_1_name, ratings$M)</pre><pre>ggplot(ratings, aes(x = M, xmin = M-SE, xmax = M+SE, y = actor_1_name )) +<br> geom_point() + <br> geom_segment( aes(x = M-SE, xend = M+SE,<br> y = actor_1_name, yend=actor_1_name)) +<br> theme(axis.text=element_text(size=8)) +<br> xlab(“Mean rating”) + ylab(“First Actor”)</pre><blockquote>นี่คือ output จากการ plot</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTEzceDYUxrX9qetT0rUTw.png" /></figure><p><em>คำนวณค่าเฉลี่ยและค่าเบี่ยงเบนมาตรฐานของผู้กำกับ (director) เพื่อจะนำไป plot และ </em>preprocess ตัวที่มี rating ไม่ผ่านเกณฑ์ขั้นต่ำที่จะนำมา plot</p><pre>ratingdat &lt;- ddply(df, c(“director_name”), summarise,<br> M = mean(imdb_score, na.rm=T),<br> SE = sd(imdb_score, na.rm=T)/sqrt(length(na.omit(imdb_score))),<br> N = length(na.omit(imdb_score)))<br>ratings&lt;-ratingdat[which(ratingdat$N&gt;=10 &amp; !(ratingdat$director_name==’’)),]</pre><p><em>นำข้อมูลผู้กำกับเปลี่ยนเป็น factor ที่จัดลำดับแล้วเรียงจากค่าเฉลี่ยของ rating และ plot</em></p><pre>ratings$director_name &lt;- factor(ratings$director_name)<br>ratings$director_name &lt;- reorder(ratings$director_name, ratings$M)</pre><pre>ggplot(ratings, aes(x = M, xmin = M-SE, xmax = M+SE, y = director_name )) +<br> geom_point() + <br> geom_segment( aes(x = M-SE, xend = M+SE,<br> y = director_name, yend=director_name)) +<br> theme(axis.text=element_text(size=8)) +<br> xlab(“Mean rating”) + ylab(“Director”)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4YkHZzDDzOz381fX_NdKUg.png" /></figure><blockquote>หลังจากได้ผลลัพธ์ออกมาจะเห็นได้ว่า นักแสดงที่ rank สูงสุดจาก ค่าเฉลี่ย rating ภาพยนตร์ที่เขาได้แสดงคือ ‘Leonardo Dicaprio’ ส่วนผู้กำกับคือ ‘David Fincher’</blockquote><blockquote>สมกับที่พี่ Leonardo Dicaprio เขาได้รับรางวัล Oscar สาขานักแสดงชายยอดเยี่ยมกันเลยใช่ไหมครับ</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*ElWFOdj2RBTXG8sL." /></figure><blockquote>เห็นไหมครับการวิเคราะห์ข้อมูลไม่ได้ยากอย่างที่คิดเพียงแต่มีความรู้ทางสถิติเพียงน้อยนิดก็สามารถทำได้ง่ายๆ นอกจากนี้ภาษา Python และ Matlab ก็ยัง support ทางด้านนี้ได้ดีพอๆกับการใช้ภาษา R เลยครับ</blockquote><p><a href="https://medium.com/@sirawittakeo/data-analysis-with-r-3-1a4e6aa7c779"><strong><em>to be continued . . .</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2f481d12880" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Analysis with R #3]]></title>
            <link>https://medium.com/@sirawittakeo/data-analysis-with-r-3-89b79779295f?source=rss-1ab7fae7047b------2</link>
            <guid isPermaLink="false">https://medium.com/p/89b79779295f</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sirawit Takeo]]></dc:creator>
            <pubDate>Wed, 26 Apr 2017 05:28:13 GMT</pubDate>
            <atom:updated>2018-12-14T06:36:34.720Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>ในภาษา R ที่เด่นๆมากกว่าภาษาอื่นก็จะเป็น function ทางคณิตศาสตร์และสถิติ กับการทำ Visualization เนี่ยแหละ</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Nnpf_R9j5z6l7doABkIdQ.jpeg" /></figure><p><strong>Visualization </strong><em>ก็คือการสร้างภาพนั่นเองครับ หมายถึงว่าการทำให้เห็นภาพ การ ทำให้มองเห็นว่าเป็นอย่างไรจากข้อมูลที่เราได้ศึกษา</em></p><blockquote>ดูจาก <strong>CHEATSHEET </strong>แล้วไปลองศึกษากันได้ง่ายมากๆครับ</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*Midb-LXSc36HVVWHjk7Yeg.jpeg" /></figure><blockquote>จะเห็นได้ว่าเราสามารถลองฝึกพล็อตกราฟในรูปแบบต่างๆได้ง่ายมาก <br>มาดูกันเลยครับ</blockquote><p><em>ตัวอย่างการทำ Visualization เป็น Histogram จากข้อมูลที่ random แบบ normal distribution 1000 จำนวน mean = 80 และ sd = 20</em></p><pre>score &lt;- rnorm(n=1000, m=80, sd=20)<br>hist(score) </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*hqXCFE8IJqcH5ryh8ShJtw.png" /></figure><pre>histinfo &lt;- hist(score)<br>histinfo</pre><p><em>จะได้ output ที่ print information ของ score แบบนี้</em></p><pre><strong>$breaks<br> [1] 10 20 30 40 50 60 70 80 90<br>[10] 100 110 120 130 140 150</strong></pre><pre><strong>$counts<br> [1] 2 11 8 41 91 160 195 205 145<br>[10] 76 46 16 2 2</strong></pre><pre><strong>$density<br> [1] 0.0002 0.0011 0.0008 0.0041 0.0091<br> [6] 0.0160 0.0195 0.0205 0.0145 0.0076<br>[11] 0.0046 0.0016 0.0002 0.0002</strong></pre><pre><strong>$mids<br> [1] 15 25 35 45 55 65 75 85 95<br>[10] 105 115 125 135 145</strong></pre><pre><strong>$xname<br>[1] “score”</strong></pre><pre><strong>$equidist<br>[1] TRUE</strong></pre><pre><strong>attr(,”class”)<br>[1] “histogram”</strong></pre><p><em>สร้าง histogram ตั้งชื่อแกน x ชื่อของกราฟ ใช้สีที่พล็อตเขียวอ่อน กำหนดขอบเขตที่แกน x </em>(0,150) ที่แกน y (0,0.02) และสร้างเส้นโค้งบน histogram ใช้สีน้ำเงินเข้ม ความหนาของเส้นระดับ 2</p><pre>hist(score, freq=FALSE, xlab=”Score”, main=”Distribution of score”, col=”lightgreen”, xlim=c(0,150), ylim=c(0,0.02))</pre><pre>curve(dnorm(x, mean=mean(score), sd=sd(score)), add=TRUE, col=”darkblue”, lwd=2)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*aYdPKWS6AdLAYyzBjfG5Sg.png" /></figure><blockquote>เห็นไหมครับง่ายนิดเดียวแต่กลับทำ Visualization ออกมาได้ดีมากๆกันเลยทีเดียว</blockquote><p><a href="https://medium.com/@sirawittakeo/data-analysis-with-r-3-b2f481d12880"><strong><em>to be continued . . .</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89b79779295f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Analysis with R #2]]></title>
            <link>https://medium.com/@sirawittakeo/data-analysis-with-r-2-1366d62e3f36?source=rss-1ab7fae7047b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1366d62e3f36</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sirawit Takeo]]></dc:creator>
            <pubDate>Thu, 30 Mar 2017 20:17:11 GMT</pubDate>
            <atom:updated>2017-04-26T05:57:54.206Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>มาดูการใช้งานเบื้องต้นกับภาษา R กันเลยนะครับผม จากตอนที่แล้ว</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*D1KFK3oWK7a5w2rxBxnSBA.jpeg" /></figure><h4>1. Editor</h4><p>หน้าต่างส่วนของ<em> editor </em>เป็นไฟล์<em>.r </em>วิธีรันบนคอนโซลคลุมชุดคำสั่งไว้แล้ว<em> Ctrl+Enter</em></p><h4>2. Console</h4><p>หน้าต่างสำหรับการรันชุดคำสั่งและโชว์ผล รวมทั้งการรายงานข้อผิดพลาดของคำสั่ง</p><h4>3. Environment/History</h4><p>หน้าต่างที่เก็บค่าของตัวแปรไว้และประวัติชุดคำสั่งที่ถูกรันผ่านคอนโซล</p><h4>4. Files/Plots/Packages/Help/Viewer</h4><p>หน้าต่างส่วนที่โชว์ไฟล์ที่กำลังอยู่ในโฟลเดอร์หลักที่ใช้งาน<br>โชว์พล็อตกราฟ (<em>Visualization</em>)<br>แพ็คเกจไลบรารี่ในการในการใช้งานฟีเจอร์ต่างๆ<br>และการช่วยเหลือ โดยการ <em>‘?ตามด้วยฟังก์ชันหรือแพ็คเกจต่างๆ’ </em>เช่น<em> ?plot</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQ2EEGmaNX6OtedIH2-ARQ.jpeg" /><figcaption>ง่วงนอนจางงงงง ..zzZZ</figcaption></figure><h4><strong>การใช้งานภายในโปรแกรม</strong></h4><blockquote>‘ [1] ’ ข้างหน้า output นี่คือเลขบรรทัดใน output จาก console</blockquote><p><strong>1. Basics</strong><br>1 + 1 <br>[1] 2<br>&quot;Hi&quot; <br>[1] “Hi”<br>height &lt;- 2<br>width &lt;- 4<br>area &lt;- height * width<br>area <br>[1] 8<br><em>เก็บลงในตัวแปรจะใช้ ‘&lt;-’ ไม่ใช้ ‘=’</em></p><ul><li>Comments <em>โดยใช้ ‘#’</em> area #Print the area</li><li>Workspace <em>เช็คโดยใช้</em>ls() <br>[1] “area” “height” “width”</li><li>Data Type <em>เช็คโดยใช้ </em>class() <br>- logical : TRUE, FALSE<br>- numeric : 2 (numeric), 2L (integer) ต้องมี L ตามหลังถึงจะเป็น type integer<br>- character : “Hi”<br>- atomic types อื่นๆ : double (higher precision), complex ( complex numbers), raw (store raw bytes)</li><li>Coercion การแปลง type โดยใช้ as.____()<br>as.numeric(TRUE) <em>จาก logical เป็น numeric</em><br> [1] 1<br> as.integer(&quot;4.5&quot;) จาก character เป็น integer<br> [1] 4<br>as.numeric(&quot;Hi&quot;) <em>จาก character เป็น numeric</em><br> [1] NA<br>Warning message:<br>NAs introduced by coercion <br> <em>— ถ้าจากตัวหนังสือไม่ใช่ตัวเลข จะเกิด NA</em></li></ul><p><strong>2. Vectors</strong><br>remain &lt;- c(3,4,5) <em>ใช้ c() เพื่อสร้าง vector<br>นำไปคำนวณได้ตามปกติจกับค่าทั้ง vector</em><br>remain * 2 <br>[1] 6 8 10<br>2:4 <em>คือ 2 ถึง 4 หรือ</em> c(2,3,4)</p><p><strong>3. Matrices</strong><br>matrix(1:6, nrow = 2) <br>matrix(1:6, ncol = 3) <em>ได้ผลเหมือนกัน สร้าง matrix 2x3 ข้างในมี 1 2 3 4 5 6 เรียงลงตาม column เป็น default ถ้าอยากให้เรียงไปตาม row </em><br><em>ก็เพิ่ม byrow = TRUE</em> matrix(1:6, nrow = 3, byrow = TRUE) <br><em> การสร้าง matrix สามารถสร้างโดยการรวม column และ row ได้ โดยคำสั่ง rbind และ cbind</em><br>x &lt;- 2:4 <br>y &lt;- 5:7 <br>z &lt;- rbind(x,y) <em>ก็คือการนำ vector x และ y มาชนกันเป็นแถว</em></p><p><strong>4. Factors</strong><br> blood &lt;- c(&quot;B&quot;, &quot;AB&quot;, &quot;B&quot;, &quot;O&quot;, &quot;A&quot;, &quot;O&quot;, &quot;B&quot;) <br> blood_factor &lt;- factor(blood) <br> [1] B AB O A O O A B<br>Levels: A AB B O<br><em>คือมันจะแยก character ที่ซ้ำกันออกมาเป็น level ให้เราเลย นี่คือ factor</em></p><p><strong>5. Lists</strong><br>list(&quot;Rsome times&quot;, 195, 5) <br> [[1]]<br>[1] “Rsome times”</p><p>[[2]] <br>[1] 190</p><p>[[3]] <br>[1] 5<br><em> — output จะแบ่งชัดเจนเป็น list ไว้สามารถเก็บ data type ที่ต่างกันได้ แต่ใน vector กับ matrix ทำไม่ได้</em></p><p><strong>6. Data frames</strong><br><em>สำหรับเก็บ data sets โดยเฉพาะ</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/137/1*nkrJmExkrpCbqtDfIHV5zQ.png" /></figure><p>name &lt;- c(&quot;Anne&quot;, &quot;Pete&quot;, &quot;Frank&quot;, &quot;Julia&quot;, &quot;Cath&quot;) <br>age &lt;- c(28, 30, 21, 39, 35) <br>child &lt;- c(FALSE, TRUE, TRUE, FALSE, TRUE) <br>df &lt;- data.frame(name, age, child) <br>df<br> name age child <br>1 Anne 28 FALSE <br>2 Pete 30 TRUE <br>3 Frank 21 TRUE <br>4 Julia 39 FALSE <br>5 Cath 35 TRUE</p><p><em>data set ส่วนใหญ่เราที่เห็นได้ชัดจะอ่านไฟล์จำพวก csv เก็บเป็น data frame<br>โดยใช้ </em>read.table()<em> และ </em>read.csv()</p><blockquote>เบื้องต้นก็มีเพียงเท่านี้แหละครับเราก็จะสามารถใช้งานได้แล้ว</blockquote><p><a href="https://medium.com/@sirawittakeo/data-analysis-with-r-3-89b79779295f"><strong><em>to be continued . . .</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1366d62e3f36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Analysis with R]]></title>
            <link>https://medium.com/@sirawittakeo/data-analysis-with-r-2d37bd9457d6?source=rss-1ab7fae7047b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d37bd9457d6</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Sirawit Takeo]]></dc:creator>
            <pubDate>Wed, 08 Mar 2017 05:33:11 GMT</pubDate>
            <atom:updated>2017-04-26T05:29:42.277Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong><em>Data Analysis</em></strong> with <strong><em>R #1</em></strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*wARGZJEPrY-KOyhmnf1XRA.jpeg" /></figure><blockquote>คุณรู้จัก</blockquote><blockquote><strong><em>“ Data Analysis ”</em></strong></blockquote><blockquote>ไหมครับ?</blockquote><p>เราเชื่อว่าคุณคงเคยได้ยินคำว่า Data Science ซึ่งในปัจจุบันถูกพูดถึงกันอย่างมาก ในส่วนเล็กๆส่วนนึงที่เราจะพูดถึง เกี่ยวกับการวิเคราะห์ข้อมูล (Data Analysis)</p><p>Data Analysis นั้นมีประโยชน์ที่เห็นได้ชัดเลยคือในทางธุรกิจ มันเป็น Business Intelligence อย่างหนึ่ง โดยนำข้อมูลต่างๆที่มีมากๆมาวิเคราะห์รวมกัน เพื่อปรับปรุงธุรกิจหรือการตลาดเป็นต้น หรือจะใช้ในการวิเคราะห์ข้อมูลทางด้านอื่นๆได้มากมายเพื่อประเมินความเสี่ยงต่างๆ และที่สำคัญเราต้องมีความรู้ทางด้านสถิติเบื้องต้น</p><blockquote>ประโยชน์ของ Data Analysis …<br> ข้อมูลที่ถูกวิเคราะห์ออกมาแล้วจะเป็นข้อมูลที่ช่วยเพิ่มการตัดสินใจที่ดี เพื่อปรับปรุงแผนการต่าง เพิ่มความเข้าใจกับปัจจุบันว่าเรามีแนวโน้มยังไง ถ้าเป็นทางด้านธุรกิจ เราจะสามารถนำการวิเคราะห์ที่ได้ไปเพิ่มรายได้และประสิทธิภาพให้กับธุรกิจได้ในระดับนึง</blockquote><p>เนื่องจากข้อมูลในทุกๆวันนี้มีจำนวนมากจึงกลายเป็นการท้าทายยิ่งขึ้น ตัวช่วยของเราที่ใช้การวิเคราะห์ข้อมูลก็คือ ภาษา R นั่นเอง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*VwIWeNnHXvXz7gGPhyYXog.jpeg" /></figure><blockquote>มารู้จัก ภาษา R กันเถอะครับ</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*hndNz9GVyMXtPnXXii2kPg.png" /></figure><p><em>R เป็น open source ที่มี community ที่ใหญ่พอสมควร ยิ่งในหมู่นักสถิติและแวดวง Data Science</em> ภาษา R ถูกออกแบบมา เพื่อให้ง่ายต่อการใช้งาน มีทั้งสัญลักษณ์และสูตรต่างๆทางคณิตศาสตร์มาให้ เหมาะกับการใช้ประมวลผลทางสถิติและยังแสดงผลภาพกราฟ <em>(Visualization)</em> ได้ดีมากด้วย มันจึงเป็นภาษาที่เจ๋งมากอย่างนึง สรุปได้คร่าวๆคือ</p><ul><li>มีการจัดการข้อมูล และ จัดเก็บข้อมูล ในรูปแบบต่างๆ</li><li>มี operator สำหรับการคำนวณข้อมูลทั้งในรูปแบบของ array และ matrix</li><li>สามารถทำงานร่วมกับเครื่องมือวิเคราะห์ข้อมูลอื่นๆ ได้ง่าย</li><li>ส่วนการแสดงข้อมูล เพื่อให้ง่ายต่อการวิเคราะห์</li><li>สามารถพัฒนาด้วยภาษาโปรแกรมที่มีประสิทธิภาพ ทำให้มีความยึดหยุ่นสูง</li><li>สามารถสร้างส่วนขยายด้วยการสร้าง package</li><li>สามารถพัฒนาด้วยภาษา C ได้</li></ul><blockquote>มาถึงขั้นตอนการใช้งาน!! สามารถดาวน์โหลดได้ที่ ‘<a href="https://cran.r-project.org/"><strong><em>r-project</em></strong></a>’ และ ‘<a href="https://www.rstudio.com/"><strong><em>rstudio</em></strong></a>’<strong><em><br></em></strong>Install ทั้งคู่ แต่ใช้งานผ่าน <strong><em>RStudio</em><br></strong>ติดตาม ข่าวสารและการเรียนรู้เพิ่มต่างๆเกี่ยวกับภาษา R ได้ที่ ‘<a href="https://www.r-bloggers.com/"><strong><em>R-Blogger</em></strong></a>’</blockquote><blockquote>การใช้งานเบื้องต้น</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*svavvHJGk4npWFop1kKsDw.png" /></figure><p><em>นี่คือหน้าตาของ RStudio ครับ<br>เป็น IDE (integrated development environment)ของภาษา R</em></p><p><a href="https://medium.com/@sirawittakeo/data-analysis-with-r-2-1366d62e3f36"><strong><em>to be continued . . .</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d37bd9457d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>