Re: [R] data.frame to character - thanks

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 10 Jun 2005 - 23:41:12 EST

Here is one minor improvement -- it does not overwrite the input:

replace(d,,as.matrix(d))

On 6/10/05, Muhammad Subianto <subianto@gmail.com> wrote:
> Dear all,
> Thank you very much for your help.
> I would like to thank Andy Liaw and Gabor Grothendieck for their fast help.
>
> Regards,
> Muhammad Subianto
>
> On this day 6/10/2005 2:30 PM, Liaw, Andy wrote:
> > Is this what you want?
> >
> >
> >>d[] <- lapply(d, as.character)
> >>str(d)
> >
> > `data.frame': 10 obs. of 3 variables:
> > $ x : chr "XYZ" "XYZ" "XYZ" "XYZ" ...
> > $ y : chr "A" "B" "C" "D" ...
> > $ fac: chr "B" "A" "C" "B" ...
> >
> > Andy
>
> On this day 6/10/2005 2:35 PM, Gabor Grothendieck wrote:
> > On 6/10/05, Muhammad Subianto <subianto@gmail.com> wrote:
> >
> >>Hi,
> >>Excuse me for this simple question.
> >>How to convert as.data.frame to as.character?
> >>
> >> ?data.frame
> >>
> >> > L3 <- LETTERS[1:3]
> >> > L10 <- LETTERS[1:10]
> >> > d <- data.frame(cbind(x=c("XYZ"), y=L10), fac=sample(L3, 10,
> repl=TRUE))
> >
> >
> >
> > d[] <- as.matrix(d)
> >
>
> On this day 6/10/2005 2:23 PM, Muhammad Subianto wrote:
> > Hi,
> > Excuse me for this simple question.
> > How to convert as.data.frame to as.character?
> >
> > ?data.frame
> >
> > > L3 <- LETTERS[1:3]
> > > L10 <- LETTERS[1:10]

> > > d <- data.frame(cbind(x=c("XYZ"), y=L10), fac=sample(L3, 10, repl=TRUE))
> > > d
> > x y fac
> > 1 XYZ A A
> > 2 XYZ B A
> > 3 XYZ C A
> > 4 XYZ D A
> > 5 XYZ E B
> > 6 XYZ F C
> > 7 XYZ G A
> > 8 XYZ H C
> > 9 XYZ I B
> > 10 XYZ J A
> > > str(d)
> > `data.frame': 10 obs. of 3 variables:
> > $ x : Factor w/ 1 level "XYZ": 1 1 1 1 1 1 1 1 1 1
> > $ y : Factor w/ 10 levels "A","B","C","D",..: 1 2 3 4 5 6 7 8 9 10
> > $ fac: Factor w/ 3 levels "A","B","C": 1 1 1 1 2 3 1 3 2 1
> > > d[3,]
> > x y fac
> > 3 XYZ C A
> > >
> > > as.character(d[3,])
> > [1] "1" "3" "1"
> > >
> >
> > I think as.character the result something like
> > [3] "XYZ" "C" "A"
> >
> > I don't know how to convert it.
> > Any help gratefully received.
> > Thank you very much in advance.
> > Kindly regards,
> > Muhammad Subianto
> >
> > ______________________________________________
> > 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
> >
>
>



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 Received on Fri Jun 10 23:48:21 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:30 EST