我有两个数据集,我想用R加入 -
数据集1
ID Name Date Price
1 A 2011 $100
2 B 2012 $200
3 C 2013 $300
Run Code Online (Sandbox Code Playgroud)
数据集2
ID Date Price
1 2012 $100
1 2013 $200
3 2014 $300
Run Code Online (Sandbox Code Playgroud)
left-join()在dplyrID中使用我最终会得到这个
ID Name Date.x Price.x Date.y Price.y
1 A 2011 $100 2012 $100
1 A 2011 $100 2013 $200
2 B 2012 $200
3 C 2013 $300 2014 $300
Run Code Online (Sandbox Code Playgroud)
然而,作为最终产品我想拥有的是这个
ID Name Date Price
1 A 2011 $100
1 A 2012 $100
1 A 2013 …Run Code Online (Sandbox Code Playgroud) 我想计算R中的单词共现矩阵。我有以下句子的数据框-
dat <- as.data.frame("The boy is tall.", header = F, stringsAsFactors = F)
dat[2,1] <- c("The girl is short.")
dat[3,1] <- c("The tall boy and the short girl are friends.")
Run Code Online (Sandbox Code Playgroud)
这给了我
The boy is tall.
The girl is short.
The tall boy and the short girl are friends.
Run Code Online (Sandbox Code Playgroud)
我要做的是首先列出所有三个句子中所有唯一词的列表,即
The
boy
is
tall
girl
short
and
are
friends
Run Code Online (Sandbox Code Playgroud)
然后,我想创建单词共现矩阵,该矩阵计算单词在一个句子中共共出现的次数,看起来像这样
The boy is tall girl short and are friends
The 0 2 2 2 2 2 1 1 1
boy 2 …Run Code Online (Sandbox Code Playgroud)