[R] Blanking out specific cells in a data frame
Sabatier, Jennifer F. (CDC/OID/NCHHSTP)
fvv9 at cdc.gov
Wed May 19 20:08:13 CEST 2010
Hi Ista,
Thanks a lot for your response. It looks like the solution Stefan
suggested is the same as you are and it works great.
I do know that you can't actually have unequal column lengths. The
reality is I am creating a pretty table to export to EXCEL and it
contains some summary statistics as well as the information from a
chi-square test (test stat, df, pvalue). When I added the info from the
chi-square test to the data frame it populated all the rows and I just
wanted to know how to blank them out.
Now that I have Stefan's solution, which turns all the un-needed info
into NAs I can use NAToUnkown() to blank them out completely.
Thanks, again, for getting back to me!
Jen
-----Original Message-----
From: Ista Zahn [mailto:istazahn at gmail.com]
Sent: Wednesday, May 19, 2010 1:59 PM
To: r-help at r-project.org
Cc: Sabatier, Jennifer F. (CDC/OID/NCHHSTP)
Subject: Re: [R] Blanking out specific cells in a data frame
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