How do I find the position of the first occurrence of a character string in a dataframe column?
This is to convert the following SAS code to R:
AVAL = INPUT(SUBSTR(AVALC,INDEX(AVALC,"- ")+2,1),8.);
This is a sample of the data:
AVALC
7
4
EXTREME DIFFICULTY - 4
STOPPED DOING THIS FOR OTHER REASONS OR NOT INTERESTED IN DOING THIS - 6
A LITTLE DIFFICULTY - 2
MODERATE DIFFICULTY - 3
NO DIFFICULTY AT ALL - 1
MODERATE DIFFICULTY - 3
NO DIFFICULTY AT ALL - 1
SOME OF THE TIME - 3
SOME OF THE TIME - 3
MOSTLY FALSE - 4
DEFINITELY FALSE - 5
GOOD - 3
FAIR - 3
SOME OF THE TIME - 3
NONE - 1
Some values can be converted directly to numeric values (done), extracting the numbers to a numeric field from the "-" responses is what I am trying to do.