如果字符串包含在其他字符串

时间:2016-09-26 11:47:21

标签: r

我有两组这样的数据框,我想用它们的字符串

加入它们
> part <- data.frame(name = c("I", "want", "to", "go", "there", "you", "are", "seeing"),
+                    value = c(0.77, 0.55, 0.33, 0.4, 0.5, 0.9, 1.0, 0.91))
> full <- data.frame(sentence = c("I want to go there", "you are seeing"))

如何根据句子中的姓名存在来加入他们?喜欢这个

    name value           sentence
1      I  0.77 I want to go there
2   want  0.55 I want to go there
3     to  0.33 I want to go there
4     go  0.40 I want to go there
5  there  0.50 I want to go there
6    you  0.90     you are seeing
7    are  1.00     you are seeing
8 seeing  0.91     you are seeing

1 个答案:

答案 0 :(得分:0)

你可以从

开始
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-20188fbdb2fd> in <module>()
      1 
----> 2 import matplotlib.pyplot as plt
      3 get_ipython().magic(u'matplotlib inline')

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py in <module>()
     27 from matplotlib import docstring
     28 from matplotlib.backend_bases import FigureCanvasBase
---> 29 from matplotlib.figure import Figure, figaspect
     30 from matplotlib.gridspec import GridSpec
     31 from matplotlib.image import imread as _imread

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py in <module>()
     34 import matplotlib.colorbar as cbar
     35 
---> 36 from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
     37 from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
     38 from matplotlib.legend import Legend

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py in <module>()
     18 import matplotlib.colors as mcolors
     19 import matplotlib.contour as mcontour
---> 20 import matplotlib.dates as _  # <-registers a date unit converter
     21 from matplotlib import docstring
     22 import matplotlib.font_manager as font_manager

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/dates.py in <module>()
    117 
    118 
--> 119 from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
    120                             MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY,
    121                             SECONDLY)

/Library/Python/2.7/site-packages/dateutil/rrule.py in <module>()
     17 
     18 from six import advance_iterator, integer_types
---> 19 from six.moves import _thread
     20 import heapq
     21 

ImportError: cannot import name _thread

从那里开始工作:

工作但可能效率不高的例子:

sapply(part$name, function(x) {grepl(full[1,1],pattern = x)})