# [R] parsing problem

Gabor Grothendieck ggrothendieck at gmail.com
Mon Feb 2 14:03:55 CET 2009

```Try using dput when posting (which gives us):

dd <- structure(list(X2 = 3:6, Placebo = structure(c(2L, 3L, 4L, 1L
), .Label = c("1000mg/kg", "125mg/kg", "250mg/kg", "500mg/kg"
), class = "factor")), .Names = c("X2", "Placebo"), class =
"data.frame", row.names = c("1",
"2", "3", "4"))

# assuming dd above try this:

library(gtools)
mixedsort(dd\$Placebo)[1]

On Mon, Feb 2, 2009 at 7:42 AM, Ken Knoblauch <ken.knoblauch at inserm.fr> wrote:
> Ken Knoblauch <ken.knoblauch <at> inserm.fr> writes:
>
>>
>> venkata kirankumar <kiran4u2all <at> gmail.com> writes:
>> > I am trying to parse a vector for caliculating minimum in that vector the
>> > vector having values like
>> >
>> > 1        Kontrolle
>> > 2          Placebo
>> > 3         125mg/kg
>> > 4         250mg/kg
>> > 5         500mg/kg
>> > 6        1000mg/kg
>> > hear i tries for comverting it into numeric with using  "as.numaric()"
>> >  function
>> > but i got values like
>> > 5
>> > 6
>> > 2
>> > 3
>> > 4
>> > 1
>> >
>> > can anyone suggest how I will solve it
>> >
>> >
>> > regards;
>> > kiran
>> >
>> Your Kontrolle is being treated as a factor so you
>> are seeing only the codes of the levels.  There is
>> probably something more elegant, but you need
>> something like,
>>
>> as.numeric(sapply(with(dd, strsplit(levels(Placebo)[Placebo], "m")), "[[", 1))
>>
> I should have specified that when I read in your data, my data frame
> looked like this
> dd
>  X2   Placebo
> 1  3  125mg/kg
> 2  4  250mg/kg
> 3  5  500mg/kg
> 4  6 1000mg/kg
> and
> str(dd)
> 'data.frame':   4 obs. of  2 variables:
>  \$ X2     : int  3 4 5 6
>  \$ Placebo: Factor w/ 4 levels "1000mg/kg","125mg/kg",..: 2 3 4  1
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help