Fran Martinez
Fran Martinez

Reputation: 679

How subset dataframe based on last row of dataframe?

I have a dataframe that contains 600 rows and More than 20K columns. Row number 600 contains number 8, 9, and 10.

I need to subset the original dataframe into:

I know this should be easier with transpose function, but later on I need to represent the images and none of the images are matching. The issue is that I'm trying to see if not transposing the data as I retrieve it from the original file, actually helps me to solve my image presentation issue.

        original_df <- as.data.frame(file)
        data8 <- original_df [(original_df [785,] == 8),]

Data frame contains again, 0 and 1's for the image. The last row contains numbers 8, 9, 10. I want to filter to data8 to contain all columns with row 600th being number 8.

Thanks,

Upvotes: 1

Views: 395

Answers (1)

IRTFM
IRTFM

Reputation: 263331

(I don't understand your concern about transposing.) The j-position (column selection) for arguments to "[" can be logical. (And it appears you are already thinking of something similar except your choice of the 785th row doesn't fit the problem description.

data8 <- data[ , data[600, ] == 8 ]
data9<- data[ , data[600, ] == 9 ]
data10<- data[ , data[600, ] == 10 ]

Upvotes: 1

Related Questions