appleLover
appleLover

Reputation: 15691

Select non NA data from Single Row

This should be pretty easy, not sure what I'm missing here. I want to select a single row from a data frame, let's say row 1000, and get all columns where that specific row is not NA.

This works

df<- df[1000,]
df<- df[, !is.na(df)]

This fails

df<- df[1000, !is.na(df)] 
ERROR "undefined columns selected"

Upvotes: 0

Views: 57

Answers (1)

Jilber Urbina
Jilber Urbina

Reputation: 61154

You missed indexing the part concerning with is.na, here's an approach:

df <- df[1000, !is.na(df[1000, ])]

Upvotes: 2

Related Questions