[R] How to handle "~" character after csv importation
Sébastien
pomchip at free.fr
Sat Aug 23 00:11:15 CEST 2008
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
More information about the R-help
mailing list