Home > OS >  How this below R code equivalent to Julia code?
How this below R code equivalent to Julia code?

Time:11-05

enter image description here

I am trying some julia code as shown here:

enter image description here

However, I get an error:

enter image description here

CodePudding user response:

In Julia 1 and 1.0 are different. 1 is an Integer while 1.0 is a floating point number. R only has floating point numbers. you want x and y to be Integers.

CodePudding user response:

You are most likely using incorrectly the filtering. Suppose you have a data frame:

data = DataFrame(a=1:6, b='a':'f');

One way to filter would be to use a BitVector such as:

julia> rows = data.a .< 3
6-element BitVector:
 1
 1
 0
 0
 0
 0

julia> data[rows, :]
2×2 DataFrame
 Row │ a      b
     │ Int64  Char
─────┼─────────────
   1 │     1  a
   2 │     2  b

You could of course just write data[data.a .< 3, :]

If you want to use filter instead the code could look like this:

julia> filter(row -> row.a  < 3, data)
2×2 DataFrame
 Row │ a      b
     │ Int64  Char
─────┼─────────────
   1 │     1  a
   2 │     2  b
  • Related