[R] Question On Regex and DataFrame

kalyan chakravarty kalyanchakravarty456 at gmail.com
Sun Feb 21 18:43:07 CET 2016


Hi,
I am new to R and learning the basics.so i came to know that data frame can
store any data type as oppose to matrix which stores only numeric.My
question is
1.)How to replace a particular pattern with new pattern in data frame.I
tried something like
x = as.data.frame(gsub(".*LINK.*","NA",file))........but the output is
really weird it converts every thing in zeros and ones.

what i actually want is DELETE ALL THE RANDOM COLUMS IN DF BASED ON ROW
VALUE.

file = read.csv("x.csv",header=T,sep=",")#read the file
file[file == "LINK"] = NA #replaced row pattern with NA
file[,colSums(is.na(file))==0] #deleting all colums which has na's

This approach pretty much does the thing but i want to get familiar on how
to use regular expressions over data frame.
Any suggestions on which function/package/regex to use when dealing with
DataFrame

Sorry if this is a basic question.
Thank you

	[[alternative HTML version deleted]]



More information about the R-help mailing list