mrafi
2008-Jan-02 13:14 UTC
[R] how to ignore or omit somethings while reading the data table
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.
Richard Müller
2008-Jan-02 13:20 UTC
[R] how to ignore or omit somethings while reading the data table
Am Mittwoch, 2. Januar 2008 14:14 schrieb mrafi:> 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 columncsv?> 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...!!!I'd like to have it simple... open your csv-file in a text editor, with "find/replace" replace your "$" by "" -- Richard M?ller - Am Spring 9 - D-58802 Balve-Eisborn www.oeko-sorpe.de
jim holtman
2008-Jan-02 13:35 UTC
[R] how to ignore or omit somethings while reading the data table
Here is a way of doing it:> x <- "1 2 $.05+ 3 4 $1.05 + 5 6 $23.56"> x <- read.table(textConnection(x)) > xV1 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> xV1 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?