+2 votes
in Programming Languages by (60.0k points)

I am trying to select some of the rows from a data frame, but it is giving the error.

My original dataframe has records from different iterations. I want to select records from iteration number 1. Here is the code I am using. v0 is the dataframe that has column iteration.

v <- v0[v0$iteration==1]

The error message is as follows. How to fix it?

Error in `v0[v0$iteration == 1]`:

! Must subset columns with a valid subscript vector.

ℹ Logical subscripts must match the size of the indexed input.

✖ Input has size 5 but subscript `v0$iteration == 1` has size 45550. 

1 Answer

+1 vote
by (354k points)
selected by
 
Best answer

You are missing a comma (,) in the code to select all columns. If you want to select some specific columns, you need to specify them.

If you want to select all columns, make the following small change in your code:

from

v <- v0[v0$iteration==1]

to

v <- v0[v0$iteration == 1,]

Related questions


...