Archive for April 8th, 2014

Nice post on Julia meta operations

Great post about basic Julia stuff @ Julia Helps

Tags:

Sample with replacement from DataFrame in Julia

julia> df = DataFrame(A = 1:10, B = 2:2:20)

10x2 DataFrame
|-------|----|----|
| Row # | A | B |
| 1 | 1 | 2 |
| 2 | 2 | 4 |
| 3 | 3 | 6 |
| 4 | 4 | 8 |
| 5 | 5 | 10 |
| 6 | 6 | 12 |
| 7 | 7 | 14 |
| 8 | 8 | 16 |
| 9 | 9 | 18 |
| 10 | 10 | 20 |

julia> df[sample([1:size(df,1)],20),:]

20x2 DataFrame
|-------|----|----|
| Row # | A | B |
| 1 | 2 | 4 |
| 2 | 3 | 6 |
| 3 | 1 | 2 |
| 4 | 4 | 8 |
| 5 | 3 | 6 |
| 6 | 5 | 10 |
| 7 | 8 | 16 |
| 8 | 5 | 10 |
| 9 | 4 | 8 |
| 10 | 8 | 16 |
| 11 | 9 | 18 |
| 12 | 10 | 20 |
| 13 | 9 | 18 |
| 14 | 4 | 8 |
| 15 | 1 | 2 |
| 16 | 1 | 2 |
| 17 | 3 | 6 |
| 18 | 4 | 8 |
| 19 | 10 | 20 |
| 20 | 7 | 14 |

Tags:

Convert a matrix (Array) of Any to a matrix (Array) of floats in Julia


convert(Array{Float64},array_of_Anys)

Tags:

Sample with replacement from Matrix in Julia

julia> sample([1 2 3;4 5 6;7 8 9], 10)
10-element Array{Int64,1}:
1
3
7
3
8
6
3
7
5
4

Tags:

Sample with replacement from a vector in Julia

julia> sample([1 2 3], 10)
10-element Array{Int64,1}:
2
3
2
3
1
1
2
1
1
1

Tags: