Re: [R] how to ignore or omit somethings while reading the data table

From: mrafi <confessin_at_gmail.com>
Date: Wed, 2 Jan 2008 06:13:38 -0800 (PST)

yeah..that worked for me...thanks...!!

jholtman wrote:
>
> Here is a way of doing it:
>

>> x <- "1 2 $.05

> + 3 4 $1.05
> + 5 6 $23.56"
>> x <- read.table(textConnection(x))
>> x

> V1 V2 V3
> 1 1 2 $.05
> 2 3 4 $1.05
> 3 5 6 $23.56
>> # delete "$" and convert to numeric
>> x$converted <- as.numeric(sub("\\$", "", as.character(x$V3)))
>> str(x)

> 'data.frame': 3 obs. of 4 variables:
> $ V1 : int 1 3 5
> $ V2 : int 2 4 6
> $ V3 : Factor w/ 3 levels "$.05","$1.05",..: 1 2 3
> $ converted: num 0.05 1.05 23.56
>> x

> V1 V2 V3 converted
> 1 1 2 $.05 0.05
> 2 3 4 $1.05 1.05
> 3 5 6 $23.56 23.56
>
>
> On Jan 2, 2008 8:14 AM, mrafi <confessin_at_gmail.com> wrote:
>>
>> hello respected ppl...
>> am a engg. student...i was trying to use R in statistical calculations
>> now the problem is..i imported a huge tsv file onto R...it has a column
>> which gives cost...and it has "$" with each numerical value in this
>> column...it is something like this..$.05,$.1,$.075...and so on..
>> R is reading it as "character vector"...
>> i tried using all the arguments but could only change it to a "factor"
>> i want to read it as numericals...and perform further operations..
>> i know it is a stupid problem but can any1 help me get outta this...
>> thank you all...!!!
>> --
>> View this message in context:
>> http://www.nabble.com/how-to-ignore-or-omit-somethings-while-reading-the-data-table-tp14578131p14578131.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>

>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>
> ______________________________________________
> 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.
>
>
-- 
View this message in context: http://www.nabble.com/how-to-ignore-or-omit-somethings-while-reading-the-data-table-tp14578131p14579043.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.
Received on Wed 02 Jan 2008 - 14:18:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Jan 2008 - 15:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive