Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a specific row in Julia

Tags:

julia

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

like image 902
Nico Avatar asked Dec 21 '16 13:12

Nico


People also ask

How do you delete a row?

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.

How do I remove rows from condition r?

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).


2 Answers

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
like image 156
DNF Avatar answered Oct 16 '22 19:10

DNF


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  
like image 21
Rajat Sarkar Avatar answered Oct 16 '22 20:10

Rajat Sarkar