[R] Removing funny characters from a column of a data frame
Bansal, Vikas
vikas.bansal at kcl.ac.uk
Sun Aug 7 21:57:19 CEST 2011
Dear all,
The 5th column of my data frame is like this-
.$.$.$.$.$,$,$...,,,,,.,,.,,...,,,,.,,....,,,T...,,,,,,,,,,,.,,,,,....,,...,,
,..,,....,,,,,...,,,..,,......,,,,,,,....,,,.,,,,....,,...G.,,,,,,,,...,,,,,,.,,
,t.,,c,,.a.,,,.A,,,,....,,,.....,,,,..........,,,,,..,,,.,,,....,,,,,...,,,$....
.,,,,..,,,...,,,,,..,,,,,,.............$..,,,,,,...,,..,,$,...,,,,,,,....,,,,,,.
,,,,......,,,,.,,.......,.....,,,,,,.,,..,,...,,,,,.,......,.......,,....,,,,..,,
,,,,.........,,,,,.....,,,,...,,,.....,,.....,,......,....,,......,.,,..,,,,...,,
H.,,,..,,.....,,,,..,,,,,,,,,^~.^~.^\".^~.^~.^~.^~,^~,^~,^~,"
I just want to have A,a,C,c,G,g,T,t and dot and comma in the columns.
example of first row should be-
.....,,...,,,,,.,,.,,...,,,,.,,....,,,T...,,,,,,,,,,,.,,,,,....,,...,,
currently i am using this code-
df$V5 <- apply(df, 1, function(x) gsub("\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10|~|H", "",x[5]))
this use of gsub looks odd to me,although result is coming good but I want something fast because data is large.I want something like this-
delete everything else except A,a,C,c,G,g,T,t and dot and comma.
Any suggestions Please.
Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
More information about the R-help
mailing list