How can I delete a specific row in Julia? Let's say I have an array:
[A , 2
B , 4
C , 6]
I want to delete the lines for which 'B' is in the first column. I can identify which row this is, but am not able to delete this row. Can anybody help me?
Thanks,
Nico
Right-click in a table cell, row, or column you want to delete. On the menu, click Delete Cells. To delete one cell, choose Shift cells left or Shift cells up. To delete the row, click Delete entire row.
For example, we can use the subset() function if we want to drop a row based on a condition. If we prefer to work with the Tidyverse package, we can use the filter() function to remove (or select) rows based on values in a column (conditionally, that is, and the same as using subset).
julia> a = rand(1:10, 5,3)
5×3 Array{Int64,2}:
4 5 7
8 4 3
8 6 3
10 4 1
9 3 10
To delete row 4:
julia> row = 4
julia> a = a[setdiff(1:end, row), :]
4×3 Array{Int64,2}:
4 5 7
8 4 3
8 6 3
9 3 10
Say you have a dataframe called "data".
julia> data=DataFrame(rand(1:10, 5,3))
5×3 DataFrames.DataFrame
Row x1 x2 x3
1 9 1 1
2 8 5 8
3 9 2 2
4 9 6 5
5 3 8 7
You want to delete entire row where column x1 has value 8.
julia> data[data[:x1].!=8,:]
4×3 DataFrames.DataFrame
Row x1 x2 x3
1 9 1 1
2 9 2 2
3 9 6 5
4 3 8 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With