[英]Subtracting one data frame column from another in R
I have a data frame as following: 我有一个数据框如下:
text class.negative class.positive class.trust
<fctr> <dbl> <dbl> <dbl>
firmly believe... 11 24 3
when i thought... 3 3 4
fans of david... 11 24 12
just watched... 3 5 9
i was so looking... 16 9 10
Here's the code I used for data manipulation 这是我用于数据操作的代码
clean.reviews = data.frame(text = reviews,class = get_nrc_sentiment(reviews), stringsAsFactors = T)
head(clean.reviews)
clean.reviews1 = as.data.frame(clean.reviews)
head(clean.reviews1)
I'm very new to data manipulation, and a little desperate with transforming data into the following: 我对数据处理非常陌生,并且非常想将数据转换为以下内容:
class (class.positive-class.negative) text
13 firmly believe...
0 when I thought...
13 fans of david...
2 just watched...
-7 i was so looking...
I realize that I might be insufficient in fully describing the situation, so I've uploaded the .csv file to dropbox . 我意识到我可能不足以完整描述这种情况,因此我已将.csv文件上传到dropbox 。
The dplyr
package will probably be the easiest way for this. dplyr
软件包可能是最简单的方法。
library(dplyr)
clean.reviews %>% mutate(class = class.positive - class.negative)
If you want to get rid of exisiting columns, replace mutate
with transmute
. 如果要摆脱现有的列,请将mutate
替换为transmute
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.