How can I remove NULL values from a dataframe in R? -


i made function in r accepts string , outputs patterns in it. example, string, "abcabcabc", outputs "abc" if have string as, "abcdefghi", outputs, " ". now, on running function on dataframe containing 1000's of rows, obtained output, output dataframeconsists of several rows having " " output. how can remove this? output dataframe of following type:

1 2 abc 2 3 bc 3 4 t 4 5 " " 5 3 ui 

so, want remove row containing values in first 2 columns 4 , 5. thanks!

an empty string not null (try is.null(" ")). you're seeing factor level " " (nothing between quotes). can remove rows of data.frame searching string.

xy[!xy$col %in% " ", ] # added ! select inverse, advertized 

or if appropriate, can merge other factor level redefining levels(xy).

here's example

set.seed(357) xy <- data.frame(first = c("a", "a", "b", "b", "b", " ", " ", " ", "d", "d"),                   second = runif(10))  xy[!xy$first %in% " ", ] # can select multiple values (see below) xy[!xy$first == " ", ] # alternative, can select 1 value  # bonus xy[!xy$first %in% c("a", " "), ] 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -