Hello, Would anyone kindly tell me how to remove the empty element in the vector object? For example, > x [1] "a" "" "" "c" "c" "c" "d"> unique(x)[1] "a" "" "c" "d" How could I get the output like: "a","c","d"? Thanks, Yanqin --------------------------------- Get your email and more, right on the new Yahoo.com [[alternative HTML version deleted]]
On Thu, 2006-10-19 at 12:23 -0700, Yanqin Yang wrote:> Hello, > > Would anyone kindly tell me how to remove the empty element in the vector object? > For example, > > x > [1] "a" "" "" "c" "c" "c" "d" > > unique(x) > [1] "a" "" "c" "d" > How could I get the output like: "a","c","d"? > > Thanks, > > YanqinIt depends upon what you mean by removing the empty elements. If you want to just get the set of values that are not "":> x[x != ""][1] "a" "c" "c" "c" "d" If you want the output exactly as you have it above, which is eliminating the repeated values:> unique(x[x != ""])[1] "a" "c" "d" See ?Extract, ?Comparison and ?Syntax for more information. HTH, Marc Schwartz
How about x[-c(2, 3)] -roger Yanqin Yang wrote:> Hello, > > Would anyone kindly tell me how to remove the empty element in the vector object? > For example, > > x > [1] "a" "" "" "c" "c" "c" "d" >> unique(x) > [1] "a" "" "c" "d" > How could I get the output like: "a","c","d"? > > Thanks, > > Yanqin > > > > --------------------------------- > Get your email and more, right on the new Yahoo.com > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/