Skip to content

Commit a299504

Browse files
committed
added R help
1 parent cc52701 commit a299504

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The concepts presented here will be new for some of you, or you may already be w
88
There is no way we can teach you everything about coding in 2 hours, however we can
99
give you the basic knowledge you will need to get started, and point you in the right direction for learning more.
1010

11-
So, we're going to cover coding basics, how to organise your work, some of the main
11+
So, we're going to cover coding basics, how to organise your work, and some of the main
1212
packages used by the different languages for things such as charting and data analysis.
1313

1414
At some point in your training or work, you will have come across one or more of the

img/r-help-1.png

40.1 KB
Loading

img/r-help-2.png

32.8 KB
Loading

programming-fundamentals.md

+29-34
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
In the introduction below, the syntax is python.
55

66
## Commands
7-
Python, Matlab, and R are interpreted languages. That means the code is interpreted at run time (there's no pre-compiling).
7+
Python, Matlab, and R are interpreted languages. That means the code is interpreted at run-time (there's no pre-compiling).
88
Commands are given to the interpreter, either as a 'script', or in an interactive session.
99
The interpreter 'interprets' the code, translate it to binary CPU instructions, executes these instructions, and returns the result (if any).
1010

1111
## Variables & Datatypes
1212
During execution, the instructions often need to access and manipulate data stored in memory.
1313

14-
Variables are named locations of the data in the memory, are of a specific 'datatype' have a value assigned to them.
14+
Variables are named locations of the data in the memory, are of a specific 'datatype', and have a value assigned to them.
1515

1616
### Simple datatypes
1717

@@ -97,7 +97,7 @@ We've already seen the assignment operator (`=`).
9797
We also have the relational operators for comparing values (`==`, `!=`, `<`, `>`),
9898
and the logical operators (`&&`, `and`, `||`, `or`, `!`, `not`).
9999

100-
So, we've covered, datatypes, variables, and operations. Next is the conditionals.
100+
So, we've covered, datatypes, variables, and operators. Next is the conditionals.
101101

102102
## Conditionals
103103

@@ -110,9 +110,9 @@ They use keywords like `IF`, `ELSE`, and `WHILE` to test conditions and execute
110110
threshold = 40
111111
my_value = 24
112112
if(my_value >= 40):
113-
print("Threshold passed")
113+
print("Threshold passed")
114114
else:
115-
print("Threshold not passed")
115+
print("Threshold not passed")
116116
117117
# > Threshold not passed
118118
```
@@ -127,11 +127,11 @@ my_value = 41
127127
my_name = "John Smith"
128128
129129
if(my_value >= threshold and my_name == "John Smith"):
130-
print("Threshold passed by John Smith")
130+
print("Threshold passed by John Smith")
131131
elif(my_value >= threshold)
132-
print("Threshold passed by " + my_name)
132+
print("Threshold passed by " + my_name)
133133
else:
134-
print("Threshold not passed")
134+
print("Threshold not passed")
135135
136136
# > Threshold passed by John Smith
137137
```
@@ -149,8 +149,8 @@ At the end of the block we increment the counter. This will result in the code b
149149
150150
counter = 0
151151
while(counter < 5):
152-
print(counter)
153-
counter = counter + 1
152+
print(counter)
153+
counter = counter + 1
154154
155155
# > 0
156156
# > 1
@@ -169,10 +169,10 @@ the iterating counter printer into a function and call it to run the code.
169169
# python
170170
171171
def print_number_of_times(times):
172-
counter = 0
173-
while(counter < times):
174-
print(counter)
175-
counter = counter + 1
172+
counter = 0
173+
while(counter < times):
174+
print(counter)
175+
counter = counter + 1
176176
177177
number_of_times(4)
178178
@@ -192,8 +192,8 @@ in a nested format, whereby the output of one function becomes the input of anot
192192
# python
193193
194194
def calculate_something(input1,input2):
195-
intermediate = input1 * input2
196-
return intermediate
195+
intermediate = input1 * input2
196+
return intermediate
197197
198198
print(calculate_something(3,6))
199199
@@ -215,7 +215,7 @@ The definition of an object is a Class, and the instance of that Class is an obj
215215
An objects functions are known as 'methods' and the variables are known as 'properties'.
216216

217217
## Control characters
218-
Different languages use different 'control characters' for defining logical blocks executable code, for example separating out conditionals, operators, and function definitions.
218+
Different languages use different 'control characters' for defining logical blocks of executable code, for example separating out conditionals, operators, and function definitions.
219219
In Matlab and R, some control characters used are the
220220
`{}()[]`. In Python, indentation and `:` is used to specify logical blocks.
221221

@@ -233,9 +233,9 @@ In Matlab and R, some control characters used are the
233233
234234
import csv
235235
with open('eggs.csv') as csvfile:
236-
spamreader = csv.reader(csvfile)
237-
for row in spamreader:
238-
print(', '.join(row))
236+
spamreader = csv.reader(csvfile)
237+
for row in spamreader:
238+
print(', '.join(row))
239239
240240
# > Spam, Spam, Spam, Spam, Spam, Baked Beans
241241
# Spam, Lovely Spam, Wonderful Spam
@@ -254,33 +254,30 @@ with open('eggs.csv', 'w') as csvfile:
254254
```
255255

256256
Libraries and packages exist for reading and writing many file types and DB connections.
257-
Another example of when google is your friend.
257+
When looking for informtion on these resources, google is your friend.
258258

259259
Carefully plan the format and structure of your data when designing your project
260-
and writing your code. Most importantly, don't delete your raw data after you've processed it.
260+
and writing your code. Most importantly, don't delete your raw data after you've processed it, keep it stored somewhere safe.
261261

262262
## Visualisation
263263

264264
When you are investigating your data, you will often want to plot the data.
265265

266266
Various charting libraries exist for most languages, each with different levels of functionality.
267-
Some can produce very complex charts, but produce only static vector or bitmap images (ggplot2).
268-
Others have less features but are interactive by default (plotly).
267+
Some can produce very complex charts, but produce only static vector or bitmap images (`ggplot2`).
268+
Others have less features but are interactive by default (`plotly`,Matlab).
269269

270-
They generally work by providing vectors of information and various settings.
271-
272-
Some examples of these will be provided for each language.
270+
They generally work by providing vectors of information and various settings, such as type of chart, colours, legends, scale, etc.
273271

274272
## Help files
275273
R and Matlab provide offline help files for understanding package functionalities and APIs.
276-
Python's documentation is online, and packages often have readthedocs.io documentation pages.
274+
Python's documentation is online, and packages often have `readthedocs.io` documentation pages.
277275
Good documentation will give you an introduction to the package, argument settings,
278276
and expected output. You should be able to drill down to to specific functions if
279277
necessary. Learning how to read and interpret documentation will be necessary if you
280-
plan to write any code beyond really basic stuff. Even then, most coders use google
281-
for EVERYTHING.
278+
plan to write any code beyond really basic stuff. Even then, most coders use google everyday.
282279

283-
## Managing code
280+
## Managing code & version control
284281

285282
So, you've taken the leap and started coding. How should you manage the code you write?
286283
With version control! Version control enables you to 'version' your code and create 'branches'
@@ -378,8 +375,6 @@ Good organisation of your workspace will enable you to write better code, with
378375
less mistakes, and make it easier for you to come back in 6 months time and work
379376
out what the hell was going on.
380377

381-
382-
Keeping your data and code organised well will help you 6 months down the line.
383-
378+
That's the fundamentals covered, now it's on to Matlab.
384379

385380
[Matlab tutorial](https://github.com/csmsoftware/Programming-for-data-analysis-tutorial-Matlab-R-Python/blob/master/matlab.md)

r.md

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ For instance, to get the help associated with the function ```factor```:
110110
111111
?factor
112112
```
113+
![R help1](https://github.com/csmsoftware/Programming-for-data-analysis-tutorial-Matlab-R-Python/raw/master/img/r-help-1.png "R help 1")
114+
115+
![R help2](https://github.com/csmsoftware/Programming-for-data-analysis-tutorial-Matlab-R-Python/raw/master/img/r-help-2.png "R help 2")
116+
113117
Additional information is often provided together with packages on their website. Simple tutorials may be distributed as well, called *vignette*.
114118

115119

0 commit comments

Comments
 (0)