[R] Blanking out specific cells in a data frame

Ista Zahn istazahn at gmail.com
Wed May 19 19:58:55 CEST 2010


Hi Jen,
You cannot have a dataframe with unequal column lengths, so you have two 
options (well maybe more, but two that come to mind): set the values to 
missing instead of deleting them, or store your data in a list instead of a 
data frame.

For option 1 (recommended) all you need is
mydf[-1, 6] <- NA

Best,
Ista
On Wednesday 19 May 2010 1:36:50 pm Sabatier, Jennifer F. (CDC/OID/NCHHSTP) 
wrote:
> Hi R-Help,
> 
> I am a new R user.  I have used SAS for many years (just FYI on what I
> am used to and possible obstacles it presents).
> 
> I have a data frame:
> 
> mydf <-data.frame(matrix(rnorm(102), ncol=6)
> 
> I would like to be able to delete ALL the information in column 6 for
> rows 2 through r, where r=#rows.
> 
> How can I do that?
> 
> I want the resulting data frame to look like this:
> 
> X1	X2	X3	X4	X5	X6
> Data	data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> Data	data	data	data	data
> 
> 
> (Sorry for using the word "data" and not having a cut and paste of my
> actual data frame...the computer I am writing this email on does not
> have R so I have to improvise.)
> 
> Thanks,
> 
> Jen
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list