How to delete any line from a data frame in R?

Asked

Viewed 4,792 times

1

I have a data frame as follows: inserir a descrição da imagem aqui

how do I remove the first line?

  • I don’t quite understand Ben, the first line of what? if possible put the code not an image.

  • Fernando, welcome to Sopt, visit Ajuda and take the Tour. Although the question seems clear, I believe you can improve it by clarifying further your difficulties or attempts (more details), so those who can help you will have more content for it. Edit your question for both.

1 answer

4

To delete a line from data.frame you must not select that line and overwrite your data.frame.

For example, using data from data.frame of your image:

notas.inform <- data.frame(nros = c(2355, 3456, 2334, 5456),
                           turma = c("tp1", "tp1", "tp2", "tp3"),
                           notas = c(10.3, 9.3, 14.2, 15.0))

If you want to delete the first line from notas.inform, just select all lines except the first and overwrite notas.inform:

notas.inform <- notas.inform[-1, ] # deleta a primeira linha
notas.inform
  nros turma notas
2 3456   tp1   9.3
3 2334   tp2  14.2
4 5456   tp3  15.0
  • Adding, you can delete multiple lines using placing identifying them on a vector. e. g.: notas.inform[-c(1,2,3),] would return the data-frame notasinform without lines 1, 2 and 3.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.