Вопрос

I have a data frame with dimensions (21,10). I don't want the 18th row. So I've been trying to filter it out by:

filtered_data_frame <- original_data_frame[1:17+19:21,]

but the '+' is obviously the wrong character to use here. What should I use instead? I've tried ,.|:; etc!

Это было полезно?

Решение

You can do it a couple of ways. The easiest is to just take out the row you don't want, the 18th row. It's the same as taking 18 out of the sequence from 1 to 21.

> c(1:21)[-18]
## [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20 21

So on the data frame, you can remove the 18th row with original_data_frame[-18, ].

Or, you can do it the other way by taking the rows you do want

> c(1:17, 19:21)
## [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 19 20 21

which would be original_data_frame[c(1:17, 19:21), ]

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top