需要帮助将Python翻译成R以获取文本数据

时间:2017-10-26 03:12:10

标签: python r text nlp

我正在尝试创建一个仅保留另一个数据集中存在的单词的数据集。我知道如何在Python中执行此操作但需要在R中执行此操作 这是两个样本数据集。我想返回text_B中存在的text_A中的单词。

# now lets iterate each cluster, and each vm in that cluster. in this example, just dump the OS of each vm in each cluster
$clusters.Keys | %{
    $clusternm = $_
    $clusters[$clusternm].Keys | %{
        $vmnm = $_
        Write-Output "${clusternm}/${vmnm}: os: $( $clusters[$clusternm][$vmnm].os )"
    }

}
<#
taco/hot: os: win
taco/guac: os: win
foo/bar: os: win
foo/baz: os: linux
#>

输出应为: 的&#39;苹果&#39;&#39;猕猴桃&#39;&#39;苹果&#39;&#39;苹果&#39;&#39;猕猴桃&#39;

2 个答案:

答案 0 :(得分:3)

//Create your own OnDateSetListener which will be called every time you set a new date in your calendar
DatePickerDialog.OnDateSetListener myListener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
        //We will display a toast so that we see it works
        String myDate = "Year:" + year +"\nmonth:" + month + "\nDayOfMonth:" + dayOfMonth;
        Toast.makeText(getApplicationContext(),myDate,Toast.LENGTH_LONG).show();
        //Here you would add all logic you want when the user sets a new date in our DatePicker
    }
};

//We will get the current instance to initialize our DatePickerDialog
Calendar calendar = Calendar.getInstance();
DatePickerDialog dialog = new DatePickerDialog(this, myListener, calendar.get(Calendar.YEAR),
        calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));

//Display our DatePickerDialog
dialog.show();

答案 1 :(得分:0)

text_A= c('apple','cherry','kiwi','Tangerine','apple','apple','kiwi')
text_B= c('apple','banana','grapefruit','kiwi','mango','papaya', 'tangerine')

intersect(text_A, text_B)
[1] "apple" "kiwi"