Re: [R] converting string vector to integer/numeric vector

2010-09-15 Thread Uwe Ligges
On 05.09.2010 14:48, rajesh j wrote: Hi, Is it possible to convert a string vector to integer or numeric vector? In my situation I receive data in a string vector and have to convert it based on a given type. ?as.interger ?as.numeric Uwe Ligges _

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
great! Thanks On Sun, Sep 5, 2010 at 9:31 PM, Joshua Wiley wrote: > On Sun, Sep 5, 2010 at 8:36 AM, rajesh j wrote: > > No, the examples dont cover it...if i have > > dat <- list(INT = c("1","2","3"), > > NUM = c("2.34","4.56","6.78"), > > INT = c("4", "5", "6"), > >

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread Joshua Wiley
On Sun, Sep 5, 2010 at 8:36 AM, rajesh j wrote: > No, the examples dont cover it...if i have > dat <- list(INT = c("1","2","3"), >             NUM = c("2.34","4.56","6.78"), >             INT = c("4", "5", "6"), >             NUM = c("3.44")) > > I need to do a which on INT[0],NUM[0],INT[0] and NU

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
Hi, in a way similar to names(dat), can I address a particular index of every vector? like [0] of all the vectors? So that I could do something like, ints<-which(=="x") On Sun, Sep 5, 2010 at 8:34 PM, Joshua Wiley wrote: > Hi Rajesh, > > This will work, unfortunately it seems like lapply() drops

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
this should work great. thanks On Sun, Sep 5, 2010 at 8:34 PM, Joshua Wiley wrote: > Hi Rajesh, > > This will work, unfortunately it seems like lapply() drops the names > before it passes each element of the list which lead to my clumsy work > around using which(). I'm sure there are other ways

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
No, the examples dont cover it...if i have dat <- list(INT = c("1","2","3"), NUM = c("2.34","4.56","6.78"), INT = c("4", "5", "6"), NUM = c("3.44")) I need to do a which on INT[0],NUM[0],INT[0] and NUM[0]...ie the [0] index of all the vectors... and test if they

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread Joshua Wiley
On Sun, Sep 5, 2010 at 8:16 AM, rajesh j wrote: > Hi, > in a way similar to names(dat), can I address a particular index of every > vector? > like [0] of all the vectors? So that I could do something like, > ints<-which(=="x") Not sure I follow you exactly, but you can use which() with any logica

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread Joshua Wiley
Hi Rajesh, This will work, unfortunately it seems like lapply() drops the names before it passes each element of the list which lead to my clumsy work around using which(). I'm sure there are other ways. dat <- list(INT = c("1","2","3"), NUM = c("2.34","4.56","6.78"), INT

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius
On Sep 5, 2010, at 10:47 AM, rajesh j wrote: I'm sorry. you seem to have misunderstood my data representation for input. Because you did not follow the Posting Guide's advice regarding producing examples using valid R code. You give me text; I work on text. #- PLEASE do read the

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
I'm sorry. you seem to have misunderstood my data representation for input. Here's what I have c<-list(INT=c("1","2","3"),NUM=c("2.34","4.56","6.78")) I need c<-list(INT=c(1,2,3),NUM=c(2.34,4.56,6.78)) On Sun, Sep 5, 2010 at 7:57 PM, David Winsemius wrote: > So there is one item per line and the

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius
So there is one item per line and the task is to recognize the strings "INT" and "NUM" and create variables with numeric type and INT=c(2,3,4) NUM=c(2.37, 4.56) # ??? I worry that is not a full description of the task if there be more than just two variable names and if all the INTs ha

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
The string vector actually comes as a part of a list, and the vector is named "int", and the numbers are strings. I then have to make it a vector that is still called "int" and has 4,5,6 etc. the types are either integer or numeric. The number of items in the vector is unknown. here's an example,

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius
On Sep 5, 2010, at 9:22 AM, rajesh j wrote: > for e.g., I get the following as a string vector > "int" "4" "5" "6" > after reading the first element, I have to convert this to a integer > vector But what is the right answer? And what number of items are possble per line? And what are the o

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
for e.g., I get the following as a string vector "int" "4" "5" "6" after reading the first element, I have to convert this to a integer vector On Sun, Sep 5, 2010 at 6:44 PM, David Winsemius wrote: > > On Sep 5, 2010, at 8:48 AM, rajesh j wrote: > > Hi, >> >> Is it possible to convert a string v

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius
On Sep 5, 2010, at 8:48 AM, rajesh j wrote: Hi, Is it possible to convert a string vector to integer or numeric vector? In my situation I receive data in a string vector and have to convert it based on a given type. Can you give an example? I don't understand either what sort of conve

Re: [R] converting string vector to integer/numeric vector

2010-09-05 Thread Ista Zahn
See ?numeric ?integer and possible the colClasses argument of read.table -Ista On Sun, Sep 5, 2010 at 12:48 PM, rajesh j wrote: > Hi, > > Is it possible to convert a string vector to integer or numeric vector? In > my situation I receive data in a string vector and have to convert it based > on

[R] converting string vector to integer/numeric vector

2010-09-05 Thread rajesh j
Hi, Is it possible to convert a string vector to integer or numeric vector? In my situation I receive data in a string vector and have to convert it based on a given type. -- Rajesh.J [[alternative HTML version deleted]] __ R-help@r-project.or