regex - Find string match in R -
I have data with two columns and thousands of rows. Frame is like:
column 1 column 2 "This is done in 1 hour" "in 1 hour"
I get a new data is. The frame column is as follows:
Column 3 "This is done"
so basically corresponds to the string according to column 2 and the remaining Get Column 1 How is this approach?
Edit:
This problem will not be solved because the length of the wire is different, so I can not do this:
Substright (x , 3)
then I need something like grepl
mailing
You can do it with regular expressions:
& Lt; - Data. Frame (Column 1 = "This is done in 1 hour", column2 = "in 1 hour") Data $ column 3 & lt; - gsub (Data $ column2, '', data $ column1) # Change the fist parameter to the second position in the third.
EDIT: For more than 1 line, you can type
data & lt; - Use data.frame (column 1). = C ("This is done in 1 hour", "This is an exam"), column 2 = C ("1 hour", "one exam")) Data $ column 3 & lt; - mapply (gsub, data $ column2, '', data $ column1)
Comments
Post a Comment