User Tools

Site Tools


arraysortandsets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
arraysortandsets [2018/12/11 02:03]
julia [Removing all NaN and/or Missing Values]
arraysortandsets [2018/12/27 17:20] (current)
Line 11: Line 11:
  
 ```juliarepl ```juliarepl
-julia> pkgchk( [ "​julia"​ => v"1.0.2", "​StatsBase"​ => v"​0.25.0"​ ] )+julia> pkgchk.( [ "​julia"​ => v"1.0.3", "​StatsBase"​ => v"​0.25.0"​ ] );
  
 ``` ```
Line 273: Line 273:
 ``` ```
  
-To find the first zero,+To find the first matching ​zero (or other value)you can do the obvious---or you can define your own "​customized"​ `isequal` function:
  
 ```juliarepl ```juliarepl
-julia> findfirst( x->(x!=0), [1,​0,​1] ​.== 0 )+julia> findfirst( x->(x==0), [1,0,1] )  ## obvious
 2 2
 +
 +julia> findfirst( x->​(x!=0),​ [1,0,1] .== 0 )  ## overly involved
 +2
 +
 +julia> isone= isequal(1) ##​ a useful function for finding 1's and not 1's
 +(::​Base.Fix2{typeof(isequal),​Float64}) (generic function with 1 method)
 +
 +julia> findfirst( isone, [3,2,1,5,6] ) ## a '​1'​ in the 3rd position
 +3
 +
 +julia> findfirst( !isone, [1,​1,​1,​1,​3,​1,​1] ) ## a non-'​1'​ in the 5th position
 +5
 +
 ``` ```
-FIXME (Andreas) Maybe introduce `isequal(0)` and the negation `!isequal(0)`. They are convenient as predicates.+
  
  
Line 367: Line 380:
 ### Removing all NaN and/or Missing Values ### Removing all NaN and/or Missing Values
  
-FIXME (Andreas:) Here you can just write `!isnan`, instead of `x->​(!isnan(x))`.+`isnan`
  
 ```juliarepl ```juliarepl
 julia> v= [ 0.0, 2.0, NaN, 3.0, NaN ]; julia> v= [ 0.0, 2.0, NaN, 3.0, NaN ];
  
-julia> filter( x->​(!isnan(x)),​ v )+julia> filter( x->​(!isnan(x)),​ v ) # one way to filter out all NaN obs
 3-element Array{Float64,​1}:​ 3-element Array{Float64,​1}:​
  0.0  0.0
Line 378: Line 391:
  3.0  3.0
  
-julia> findall( x->​!isnan(x),​ v )+julia> filter( !isnan, v ) == v[ .! isnan.(v) ] ## two more ways to do the same 
 +true 
 + 
 +julia> findall( x->​!isnan(x),​ v ) ## find the index values of non NaNs
 3-element Array{Int64,​1}:​ 3-element Array{Int64,​1}:​
  1  1
Line 384: Line 400:
  4  4
  
-julia> v[ findall( x->​!isnan(x),​ v ) ]+julia> v[ findall( x->​!isnan(x),​ v ) ] ## so this again removes all NaN's
 3-element Array{Float64,​1}:​ 3-element Array{Float64,​1}:​
  0.0  0.0
  2.0  2.0
  3.0  3.0
 +
 +julia> ismissing.( [ 1.0, missing, 3.0 ] ) ## same trick for missing values
 +3-element BitArray{1}:​
 + false
 +  true
 + false
 +
 ``` ```
 +
  
 ### Replacing all NaN and/or Missing Values ### Replacing all NaN and/or Missing Values
arraysortandsets.1544522583.txt.gz · Last modified: 2018/12/11 02:03 by julia