[R] Identifying columns with specific character
Farnoosh Sheikhi
f@rnoo@h_81 @ending from y@hoo@com
Wed Apr 18 23:23:09 CEST 2018
Hello,
I have a data frame with 400 columns and wanted to filter character columns with "$" in it.For example: > x <- c("$5", "$89", "$10", "$34") > y <- c(1:4)> My.Data <- data.frame (x,y)> My.Data x y1 $5 12 $89 23 $10 34 $34 4
I want to detect the columns with $ and remove the $ from the selected columns.I have tried apply(My.Data, 2, function (x) any(grepl("$", x))) but it's not really working.Or: apply(My.Data, 2, function(x){x<-gsub("\\$", "", x)}) works but it turns all the columns to a factor.
Thanks.
[[alternative HTML version deleted]]
More information about the R-help
mailing list