简体   繁体   English

从R中的一个数据帧列中减去另一个

[英]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.

相关问题 从另一个时间减去一个时间列 - Subtracting one time column from another r 从数据框中的前一列中减去每一列 - Subtracting each column from its previous one in a data frame 将数据从一个数据框的列导入到R中的另一数据框? - Importing data from column of one data frame to another dataframe in r? R:从一个数据框中提取行,基于列名匹配另一个数据框中的值 - R: Extract Rows from One Data Frame, Based on Column Names Matching Values from Another Data Frame 将一个data.frame的值分配给R中另一个data.frame的特定列? - Assign value from one data.frame to a specific column of another data.frame in R? R:根据另一列操作一个数据框列的值 - R: Manipulate values of one data frame column based on another column 将值从一个数据帧添加到R中的另一个数据帧 - Add value from one data frame into another data frame in R 如何使用R从一列的字符串中提取特定数字并将其存储在数据框的另一列中? - How to extract a particular number from a string of one column and store it in another column of data frame using R? R:从数据框中的一列返回一个值,该值对应于另一列中的最小值 - R: return a value from one column in a data frame corresponding to the minimum value in another column R根据其参考列将特定列从一个数据帧合并到另一数据帧 - R merge a particular column from one data frame to another according to its reference column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM