User Tools

Site Tools


how_to_change_data.frame_into_another_data.frame_which_is_unique_about_some_id

Below is a sample.

a <- data.frame(col1 = c("a","b","c","d","e","f","g"), col2 = c(10,10,20,50,40,20,30), col3 = c(1,2,3,5,1,5,7))

I want to delete 5th row from the data.frame.

a
  col1 col2 col3
1    a   10    1
2    b   10    2
3    c   20    3
4    d   50    5
5    e   40    1
6    f   20    5
7    g   30    7

I delete by doing this.

a <- a[-5,]

Then I get this.

a
  col1 col2 col3
1    a   10    1
2    b   10    2
3    c   20    3
4    d   50    5
7    g   30    7

If I want to delete a col of the data.frame, I specify the col number and add - to the number.

a <- a[,-1]

Then, I get this.

a
  col2 col3
1   10    1
2   10    2
3   20    3
4   50    5
6   20    5
7   30    7
how_to_change_data.frame_into_another_data.frame_which_is_unique_about_some_id.txt · Last modified: 2015/08/02 02:04 by vincenzo