I have a data frame that looks like this:
ID Time Item
1 S001 P1 1/2/
2 S002 P1 2/10/7/9
3 S003 P1 1/2/4/5/6/10/9
4 S004 P1 1/2/5/6/10/7/9
5 S005 P1 1/2/10/7/9
6 S006 P1 2/5/6/7/9
I want to search the 'Item' column, and create a new column where if the Item column contains a 1, then the new column =1 and if the item column doesn't contain a 1, then the new column =0. This is similar to the grepl function, but I want it to input 1s and 0s instead of TRUE and FALSE.
That is, my data set will look like this:
ID Time Item Item1
1 S001 P1 1/2/ 1
2 S002 P1 2/10/7/9 0
3 S003 P1 1/2/4/5/6/10/9 1
4 S004 P1 1/2/5/6/10/7/9 1
5 S005 P1 1/2/10/7/9 1
6 S006 P1 2/5/6/7/9 0
I want to do this all the way up to ten columns (the idea is to turn the 'Item' column into a matrix of ones and zeros).
ID Time Item Item1 Item2 Item3 Item4 Item5 Item6 Item7
1 S001 P1 1/2/ 1 1 0 0 0 0 0
2 S002 P1 2/10/7/9 0 1 0 0 0 0 1
3 S003 P1 1/2/4/5/6/10/9 1 1 0 1 1 1 0