[R] How to handle "~" character after csv importation

jim holtman jholtman at gmail.com
Sat Aug 23 03:22:08 CEST 2008


Try 'check.names=FALSE' in the read.table call.

On Fri, Aug 22, 2008 at 6:11 PM, Sébastien <pomchip at free.fr> wrote:
> Dear R users,
>
> I have to import some csv files in which column headers contain the
> character "~". Following the following import call, the character seems to
> be replaced by dots in the column names of my data frame. Plus, I cannot
> query names(mydata) to find the column index which header should contain "~"
> or "."
>
>> mydata <- data.frame(read.table("mycsv.csv", sep = ",", header = TRUE,
>> na.strings = ".", as.is = TRUE))
>> mydata
>  P1 P2 P3 P1.P2 P1.P3 P2.P3 A B C
> 1  1  2  3     4     5     6 7 8 9
>> names(mydata)
> [1] "P1"    "P2"    "P3"    "P1.P2" "P1.P3" "P2.P3" "A"     "B"     "C"   >
> grep("~",names(mydata))
> integer(0)
>> grep(".",names(mydata))
> [1] 1 2 3 4 5 6 7 8 9
>
> How can I check for this character ? And by the way, can anyone explain to
> me the result of the last grep call?
>
> Thank you in advance.
>
> Sebastien
>
> ______________________________________________
> 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 that you are trying to solve?



More information about the R-help mailing list