Hi David,
It works for me when handling data frames mixing characters and numeric by
using either print() or a function called "foo":

# Some data
x <- c("A", "B", "C", 3.5, 1, 0, NA, "a character",NA, "another character")
mydata <- data.frame(x = x, y = sample(x))
mydata

# Option 1: print()ing
print(mydata, na.print = ".")

# Option 2: using a function "foo"
foo <- function(x){
        y <- as.character(x)
        y[is.na(y)] <- "."
        y
        }

mydata[,] <- apply(mydata, 2, foo)
mydata

See ?print for more information.

HTH,

Jorge


On Mon, Jun 22, 2009 at 9:22 AM, David_D <david.da...@gmail.com> wrote:

>
> Jorge,
>
> Thanks a lot for your reply. It's indeed working in this case. However,
> with
> data frames mixing numeric and character is not working anymore. Morever I
> am working with many variables and I don't want to modify them. What I
> would
> really appreciate is a global option (in the Rprofile?) that allow to
> change
> the display nd printing of NA by any symbol?
>
> Does it exist?
>
> Best regards,
> David
>
>
> Jorge Ivan Velez wrote:
> >
> > Dear David,
> > Try this:
> >
> > x <- c("A", "B", "C", NA)
> > x[is.na(x)] <- "."
> > x
> >
> > HTH,
> >
> > Jorge
> >
> > On Mon, Jun 22, 2009 at 2:11 AM, David_D <david.da...@gmail.com> wrote:
> >
> >>
> >> Dear R-users,
> >>
> >> For reporting purpose (using Sweave and LaTeX), I am creating complex
> >> tables
> >> with the cat function such as
> >>
> >> > x<-c("A", "B", "C", NA)
> >> > cat(x, '\n')
> >> A B C NA
> >>
> >> For convenience, I would like to change all my NA value to something
> else
> >> like '.' (as in SAS for example). Is there a global option which allows
> >> this
> >> change? Or should I change all my code to work with the print function
> >> and
> >> the na.print argument?
> >>
> >> Best regards,
> >> David
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Convert-NA-to-%27.%27-tp24142187p24142187.html
> >> Sent from the R help mailing list archive at Nabble.com.
> >>
> >> ______________________________________________
> >> R-help@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.
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Convert-NA-to-%27.%27-tp24142187p24147157.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to