-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
324 lines (213 loc) · 8.62 KB
/
README.Rmd
File metadata and controls
324 lines (213 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
---
title: "Starter Kit for Data Science (R and Python)"
author: "Algoritma Data Science School"
output:
html_document:
css: style.css
number_sections: yes
df_print: paged
highlight: tango
theme: cosmo
toc: yes
toc_depth: 3
toc_float:
collapsed: false
smooth_scroll: false
pdf_document:
toc: yes
toc_depth: '3'
github_document: null
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# 🙌 Before Start to Learn
**Mindset is everything** because our mindset will be the guiding force behind our decisions and the actions we have to take.
You must believe that **you can do it, you can learn data science as well!**
<img src="img/mindset.webp" title="Mindset is Everything" width="300"/>
# 💻 What is Programming?
Before we dive deeper, let's watch this video!
[](https://www.youtube.com/watch?v=dU1xS07N-FA)
Programming means writing instructions for a computer to perform desired actions or tasks.
For writing instruction, we need a language, as humans talk to each other. Because of the computer can't understand our natural language---such as English, Bahasa Indonesia---we need to communicate with the computer using a language that the computer understands, **programming language**.
## Programming Language
A programming language is a set of commands, instructions, and other syntax use to create a software program. The problem that programming languages solve is computers only understand 0s and 1s, but humans do not understand 0s and 1s. So, a programming language is an intermediary between a computer and a programmer.
There are hundreds of developing programming languages with various uses. The majority of popular programming languages are high-level languages (which are easy for humans to understand). Some of them, namely **Python and R**. We will learn more in [**Algoritma Data Science School**](https://algorit.ma/) course.
### R
R is the name of a programming language as well as software for data processing and graphics. R is very popular today for three reasons:
- Lots of data processing options with a very complete number of features from graphics to machine learning.
- It is faster to learn and run to process data compared to other languages.
- R is free and open source, which means there is no need for licensing fees which are usually very expensive for data processing software.
> 📌 They have many [Cheatsheets](https://www.rstudio.com/resources/cheatsheets/) for you
### Python
Python is widely used in data science and has a robust suite of powerful tools to communicate with data. Python is also popular today for three reasons:
- Python is easy to learn.
- The syntax is easy to read and understand.
- There are many useful libraries to perform computations and other operations.
> 📌 Generally, Python code is also much shorter compared to other programming languages.
However, here we will provide a little starter for those of you who want to start learning both languages for free and can be accessed life-time. Please enjoy while studying!
# 🔍 Basic Programming
## Variable
A variable is a place to store data, while a data type is a type of data stored in a variable.
<img src="img/1-variabel.png" title="Mindset is Everything" width="420"/>
So if we say, data is food, then variable is where we store the food.
**R**
Use the assignment operator `<-` to create new variables.
```{r}
x <- 5
x
```
**Python**
Use the assignment operator `=` to create new variables.
```{python}
print("Hello Python!")
x = 5
x
```
## If-Else Statement
This is one of the Decision-making statements in the programming language. It is one of the easiest decision-making statements.
<img src="img/2-ifelse.png" title="Mindset is Everything" width="420"/>
**R**
```{r}
x <- 5
if (x > 0) {
print('x is positive')
} else {
print('x is negative')
}
print('This cell execute after if-else statement')
```
**Python**
```{python}
x = -5
if (x > 0):
print('x is positive')
else:
print('x is negative')
print('This cell execute after if-else statement')
```
## Vector (R) / List (Python)
This vector in R is a place to store values for elements that have the same class. But, if we want to store elements or components that have different classes and lengths, we can use **list** both in R or Python.
**R**
In R, if we want to store elements or components that have different classes and lengths, we can use `list`, but if the classes of the element that we want to store is same, instead of `list()` we can use **concate** function or `c()` or we can call it as vector.
<img src="img/4-list-r.png" title="Mindset is Everything" width="420"/>
*Vector*
```{r}
my_vector <- c("a", "b", "c")
print(my_vector)
```
*List*
```{r}
my_list <- list("apple", 1, "cherry", my_vector)
my_list[1]
my_list[length(my_list)] # That means printing the last element
my_list[-1] # That means excluding the first element to print
```
**Python**
List in Python can be used for storing elements or components that have different classes and lengths. Python uses **zero-based indexing**. That means, the first element(value 'red') has an index 0, the second(value 'green') has index 1, and so on. **Negative indexing** in Python means the indexing starts from the end of the iterable.
<img src="img/4-list-python.png" title="Mindset is Everything" width="420"/>
```{python}
my_list = ["apple", 1, "cherry", ["a", "b", "c"]]
my_list[0]
my_list[-1] # That means printing the last element
my_list[1:] # That means excluding the first element to print
```
## Loop (For)
The for loop is used to iterate over a sequence (list) or other iterable objects.
<img src="img/3-loop.png" title="Mindset is Everything" width="420"/>
**R**
```{r}
for (i in c("apple", "banana", "cherry"))
{
print(i)
}
```
*Using `list()`*
```{r}
for (i in list("apple", 1, "cherry"))
{
print(i)
}
```
**Python**
```{python}
my_list = ["apple", 1, "cherry"]
for i in my_list:
print(i)
```
## DataFrame
DataFrame is a **data structure that organizes data into a 2-dimensional table of rows and columns**, much like a spreadsheet.
<img src="img/5-dataframe.png" title="Mindset is Everything" width="420"/>
### Create a DataFrame
**R**
For creating a DataFrame in R, we can `use data.frame()`
```{r}
iklan <- data.frame(Channel=c("Youtube", "Instagram", "Facebook", "Twitter"), budget=c(8.0, 4.5, 4.3, 2.5))
iklan
```
**Python**
For creating a DataFrame in Python, we need `pandas` library. So first of all we need import that library like this one.
```{python}
import pandas as pd
```
```{python}
iklan = pd.DataFrame({
"Channel":["Youtube", "Instagram", "Facebook", "Twitter"],
"budget":[8.0, 4.5, 4.3, 2.5],})
print(iklan)
```
### Get the Structure
**R**
One can get the structure of the data frame using `str()` function in R.
```{r}
str(iklan)
```
**Python**
One can get the structure of the data frame using `.info()` function in Python `pandas.DataFrame`.
```{python}
iklan.info()
```
### Summary of DataFrame
**R**
In R data frame, the statistical summary and nature of the data can be obtained by applying `summary()` function.
```{r}
summary(iklan)
```
**Python**
In Python `pandas.DataFrame`, the statistical summary and nature of the data can be obtained by applying `.describe()` function.
```{python}
iklan.describe()
```
### Extract Data
Extract data from a data frame means that to access its rows or columns. One can extract a specific column from a data frame using its column name.
**R**
```{r}
iklan$Channel
```
**Python**
```{python}
iklan["Channel"]
```
```{python}
iklan.Channel
```
### Expand DataFrame
**R**
A data frame in R can be expanded by adding new columns and rows to the already existing data frame.
```{r}
iklan$Color <- c("Red", "Purple", "Blue", "Soft Blue")
iklan
```
**Python**
A Python `pandas.DataFrame` can be expanded by adding new columns and rows to the already existing data frame.
```{python}
iklan["Color"] = ["Red", "Purple", "Blue", "Soft Blue"]
iklan
```
That's all basic programming that you must know before continuing the next level of data science learning.For the next level, let's learn in [Algoritma Data Science School](https://algorit.ma)
# 📖 Read More
- [R Programming, Bahasa Pemrograman dalam Big Data](https://algorit.ma/blog/r-programming-adalah-2022/)
- [Perbandingan R dan Python untuk Analisis Data](https://algorit.ma/blog/data-science/r-dan-python-untuk-analisis-data/)
- [Belajar Apa Itu Python](https://algorit.ma/blog/belajar-apa-itu-python/)
- [Belajar Apa Itu R](https://algorit.ma/blog/data-science/r-dan-python-untuk-analisis-data/)
- https://www.youtube.com/c/AlgoritmaDataScienceEducation