Hi, It appears that deal does not support missing values (NA), so I need to remove them (NAs) from my data frame. how do I do this? (I am very new to R, so a detailed step-by-step explanation with code samples would be nice). Some columns (variables) have quite a few NAs, so I would rather drop the whole column than sacrifice all the rows (observations) which have NA in that column. How do I remove a column from a data frame? Thanks! -- Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 4 (Stentz) http://ffii.org http://www.mideasttruth.com http://pmw.org.il http://www.dhimmi.com http://www.honestreporting.com http://www.jihadwatch.org Don't hit a man when he's down -- kick him; it's easier.
Hi Sam If you are new to R it will definitively pay off to start from the basics. Go to the help menu-> manuals in pdf and select "An Introduction to R". After you read that document you will be able to answer your questions :-) Good luck! Francisco>From: Sam Steingold <sds at podval.org> >Reply-To: sds at podval.org >To: r-help at stat.math.ethz.ch >Subject: [R] removing NA from a data frame >Date: Fri, 17 Mar 2006 15:17:51 -0500 > >Hi, >It appears that deal does not support missing values (NA), so I need to >remove them (NAs) from my data frame. >how do I do this? >(I am very new to R, so a detailed step-by-step >explanation with code samples would be nice). > >Some columns (variables) have quite a few NAs, so I would rather drop >the whole column than sacrifice all the rows (observations) which have >NA in that column. >How do I remove a column from a data frame? > >Thanks! > >-- >Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 4 >(Stentz) >http://ffii.org http://www.mideasttruth.com http://pmw.org.il >http://www.dhimmi.com http://www.honestreporting.com >http://www.jihadwatch.org >Don't hit a man when he's down -- kick him; it's easier. > >______________________________________________ >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
> * Francisco J. Zagmutt <trevsnygr28 at ubgznvy.pbz> [2006-03-17 21:09:48 +0000]: > > Go to the help menu-> manuals in pdf and select "An Introduction to > R". After you read that document you will be able to answer your > questions :-)I did. I still need help. The matter is not so much with "getting things done" (I can probably write the code - although I would rather not) as with not reinventing the wheel. PS. next time you decide to answer my question with "RTFM", please also include the number of the page that answers my specific question. -- Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 4 (Stentz) http://www.jihadwatch.org http://www.camera.org http://www.mideasttruth.com http://www.memri.org http://www.palestinefacts.org http://www.savegushkatif.org Type louder, please.
Sam Steingold <sds <at> podval.org> writes:> > Hi, > It appears that deal does not support missing values (NA), so I need to > remove them (NAs) from my data frame. > how do I do this? > (I am very new to R, so a detailed step-by-step > explanation with code samples would be nice).If you wanted to remove rows with NAs from data frame X na.omit(X) would do it. In this case I think X[!sapply(X,function(z)any(is.na(z)))] should work, although I haven't tested it. function(z)any(is.na(z)) looks for any NA values sapply applies the function to each element in the list (= column in the data frame) and returns a vector ! negates the logical vector [] picks the appropriate elements (=columns) out of the list (=dataframe) I haven't tested it. Conceivably X[!sapply(is.na(X),any)] or X[sapply(!is.na(X),all)] would work too, although I'm not sure. Ben
You might find the 2nd part of the following response useful https://stat.ethz.ch/pipermail/r-help/2006-March/090611.html And if you want to RTFM, I guess sections 2.5, 2.7, 5.1, 5.2 of http://cran.r-project.org/doc/manuals/R-intro.html might be useful. PS: 1) R-help is designed for and by unpaid volunteers. Therefore sometimes RTFM without page reference is quite acceptable. 2) Similar question often gets repeated over and over the list. It might be useful to search http://finzi.psych.upenn.edu/nmz.html first. On Fri, 2006-03-17 at 16:17 -0500, Sam Steingold wrote:> > * Francisco J. Zagmutt <trevsnygr28 at ubgznvy.pbz> [2006-03-17 21:09:48 +0000]: > > > > Go to the help menu-> manuals in pdf and select "An Introduction to > > R". After you read that document you will be able to answer your > > questions :-) > > I did. I still need help. > > The matter is not so much with "getting things done" (I can probably > write the code - although I would rather not) as with not reinventing > the wheel. > > PS. next time you decide to answer my question with "RTFM", please also > include the number of the page that answers my specific question. >
> * Adaikalavan Ramasamy <enznfnzl at pnapre.bet.hx> [2006-03-19 04:51:19 +0000]: > > 1) R-help is designed for and by unpaid volunteers. Therefore > sometimes RTFM without page reference is quite acceptable.I am an "unpaid volunteer" maintainer of CLISP (http://clisp.cons.org). I often answer questions with specific link to the CLISP FAQ (which really is just that - the list of the frequently asked questions). If you do not feel like answering a question, it is perfectly fine with me, I do not think that anyone owes me anything. All I am asking is that if you do decide to answer, please make your answer immediately useful, i.e., not requiring learning all the manual by heart (a specific manual section is perfectly fine though). Thanks. PS. Many thanks to Ben Bolker and Haifeng Xie for their help! PPS. how do I figure out the number of rows in a data.frame? is length(attr(X,"row.names")) the right way? -- Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 4 (Stentz) http://www.camera.org http://pmw.org.il http://www.memri.org http://www.jihadwatch.org http://www.dhimmi.com Are you smart enough to use Lisp?
> If you do not feel like answering a question, it is perfectly > fine with > me, I do not think that anyone owes me anything. > All I am asking is that if you do decide to answer, please make your > answer immediately useful, i.e., not requiring learning all > the manual by > heart (a specific manual section is perfectly fine though). > Thanks. >But do you not owe the list the courtesy of first making a reasonable attempt on your own?> PPS. how do I figure out the number of rows in a data.frame? > is length(attr(X,"row.names")) the right way?help.search("number of rows") immediately gets you your answer! -- Bert Gunter Genentech