[R] How can I delete components in a column ?
Hi all R-helpers, i am a new R-user and have problem with deleting some components in a column. I have a dataset like Name Idx empty 2 empty 3 anone2 bnone3 d none 2 ad cfh 4 bf cdt 5 empty 2 empty 2 gf cdh 4 d none 5 and want to eliminate all components that have id=none and empty . The remaining data should be Name Id x ad cfh 4 bfcdt 5 gfcdh 4 How can I do this ? The components with id=empty have no name. Thanks in advance, Regards, Yen [[alternative HTML version deleted]] __ R-help@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.
Re: [R] How can I delete components in a column ?
On Mon, 2006-10-09 at 17:15 +0200, Yen Ngo wrote: > Hi all R-helpers, > > i am a new R-user and have problem with deleting some components in a > column. I have a dataset like > > Name Idx >empty 2 >empty 3 > anone2 > bnone3 > d none 2 > ad cfh 4 > bf cdt 5 >empty 2 >empty 2 > gf cdh 4 > d none 5 > > and want to eliminate all components that have id=none and empty . The > remaining data should be > > Name Id x > ad cfh 4 > bfcdt 5 > gfcdh 4 > > How can I do this ? The components with id=empty have no name. > > Thanks in advance, > Regards, > Yen The easiest way is the use the subset() function. Presuming that your data frame is called 'DF': NewDF <- subset(DF, !Id %in% c("empty", "none")) The second argument, using a logical negation of the "%in%" function, tells subset to only select those rows where the "Id" column does not contain either "empty" or "none". See ?subset and ?"%in%" HTH, Marc Schwartz __ R-help@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.
Re: [R] How can I delete components in a column ?
Yen Ngo yahoo.se> writes: > > Hi all R-helpers, > > i am a new R-user and have problem with deleting some components in a column. I have a dataset like > > Name Idx >empty 2 >empty 3 > anone2 > bnone3 > d none 2 > ad cfh 4 > bf cdt 5 >empty 2 >empty 2 > gf cdh 4 > d none 5 > > and want to eliminate all components that have id=none and empty . The remaining data should be Take a look at the subset function. Mark Lyman __ R-help@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.