subset

Subsetting a data frame based on a logical condition on a subset of rows

心已入冬 提交于 2020-12-29 07:41:05
问题 I've tried to come up with a simple solution to the followig problem. Here is the minimum working example: data <- data.frame(subject = c('Math', 'English', 'French', 'English'), grade = c(1, 3, 5, 4)) I want a function that compares Enlish grades and returns a logical vector that has TRUE for the row with the highest english grade, and FALSE for all other rows. In this case [1] FALSE FALSE FALSE TRUE . 回答1: We can get the max 'grade' per 'subject' with ave compare it with the 'grade' to get

subsetting 1-column matrix deletes rownames [duplicate]

夙愿已清 提交于 2020-12-26 07:39:48
问题 This question already has an answer here : How to subset matrix to one column, maintain matrix data type, maintain row/column names? (1 answer) Closed 5 years ago . When I try to subset a 1-colum matrix by it's row names the subsetting works but an numeric vector is returned. can you somehow prevent that behaviour and keep the row names? M<-as.matrix(rnorm(5)) rownames(M)<-LETTERS[1:5] M [,1] A 0.6250957 B 0.7330598 C -0.7127075 D 0.2162602 E 0.2223444 M <- M[which(rownames(M) != "A")] M ##

快速配置指南_Windows的MPIO多路径

别来无恙 提交于 2020-12-19 18:06:18
1.1 安装与启用 Windows MPIO 集成在 Windows 的系统中,默认情况下不会安装,需要手动安装起来。安装步骤描述如下。 步骤 1 进入 Features 添加界面。 打开“ Server Manager ”,选择“ Feature ”,选择右键菜单中的“ Add Features ”,如下图所示。 图1-1 添加 Feature 步骤 2 添加“ MultiPath I/O ” 在弹出的 Features 选择框中,选择“ MultiPath I/O ”,如 图 1-2 所示。 图1-2 添加 Multipath I/O 框架 按照提示完成 Feature 的安装即可。 ---- 结束 1.2 配置多路径 需要对 MPIO 进行相应的配置才能让其接管存储系统。 步骤 1 查询设备 VID 和 PID 。 VID : Vendor ID ,厂商 ID 。例如 HUAWEI 等。 PID : Product ID ,产品 ID 。例如 S5500T 、 S5600T 。 安装 MPIO 多路径后, Windows 2008 及后续版本的操作系统提供 mpclaim 多路径命令可以用于查询磁盘信息。查询的命令如 图 1-3 所示。 图1-3 命令查询磁盘信息 如 图 1-3 所示, VID 为“ HUAWEI ”, PID 为“ S2600 ”。 这里显示的 PID 和

Best method to extract selected columns from 2d array in apps script

落花浮王杯 提交于 2020-12-14 12:39:18
问题 I'm working in google apps script. If I start with a range like range A1:E5, that's a 5x5 array. I want to return range C1:D5, a 5x2 array. Start with a 2d array and return only selected 'columns'. That's basically it. I think it's a fundamental operation, but I'm really struggling. I have my code below, but I'm open to any options that use arrays (not ranges, so as to avoid pinging the server unnecessarily). Note that I do want to be able to pass an array parameter for columns, so [2,3,4] or

Best method to extract selected columns from 2d array in apps script

ぃ、小莉子 提交于 2020-12-14 12:33:25
问题 I'm working in google apps script. If I start with a range like range A1:E5, that's a 5x5 array. I want to return range C1:D5, a 5x2 array. Start with a 2d array and return only selected 'columns'. That's basically it. I think it's a fundamental operation, but I'm really struggling. I have my code below, but I'm open to any options that use arrays (not ranges, so as to avoid pinging the server unnecessarily). Note that I do want to be able to pass an array parameter for columns, so [2,3,4] or

Best method to extract selected columns from 2d array in apps script

早过忘川 提交于 2020-12-14 12:33:05
问题 I'm working in google apps script. If I start with a range like range A1:E5, that's a 5x5 array. I want to return range C1:D5, a 5x2 array. Start with a 2d array and return only selected 'columns'. That's basically it. I think it's a fundamental operation, but I'm really struggling. I have my code below, but I'm open to any options that use arrays (not ranges, so as to avoid pinging the server unnecessarily). Note that I do want to be able to pass an array parameter for columns, so [2,3,4] or

【R语言学习笔记】4. 文本挖掘之情感分析

故事扮演 提交于 2020-11-10 06:28:42
1. 目的:通过分析和挖掘推特上的推文,来尽可能准确的判断其对苹果公司的态度(积极、消极、或者为其他)。 2. 数据来源: Twitter API;构建因变量方法:Amazon Mechanical Turk;自变量为推文内容。 Amazon Mechanical Turk: 亚马逊Mechanical Turk是一个众包市场,使个人或企业能够使用人工智能来执行计算机当前无法执行的任务。作为全球最大的众包市场之一,Mechanical Turk提供按需、可扩展的员工队伍,将创业公司、企业、研究人员、艺术家、知名科技公司和政府机构与个人联系起来,以解决计算机视觉、机器学习、自然语言处理等方面的问题。 tweets <- read.csv("tweets.csv", stringsAsFactors=FALSE) View(tweets)    str(tweets) # 查看数据结构    创建因变量 tweets$Negative = as.factor(tweets$Avg <= -1) table(tweets$Negative) 3. 数据预处理:词袋模型(bag of words) 创建语料库 corpus <- VCorpus(VectorSource(tweets$Tweet)) # VCorpus() creates volatile corpora. #