r - 如何将 id 列表作为列表而不将它们更改为整数
问题描述
我有一个我正在使用的调度代码列表,并且正在尝试绘制一个条形图。
问题是它们具有类似的值29D00V
,当我使用类型检查它们的类型时,它们会以整数形式出现。
我想将它们绘制为条形图的 x 轴上的分类,但是当我将它们转换为列表时,c(rows_to_use$Group.1)
它会将它们转换为整数。
例如,我怀疑它正在将它们读取为十六进制24D01
值568
,然后将它们转换为整数。有没有一种简单的方法可以将数据框的整个 Group.1 列更改为字符串类型?
这是我的脚本的当前迭代:
#read csv
df <- read.csv(file="C:/Users/GIGNWI_Ar208671/Documents/R/Projects/CallTimes/call_times/data/risks_codes_descriptions.csv",header=TRUE)
#correct garbled column name
colnames(df)[1] = "call_times"
rows_to_use <-df
#initialise new name, this is where filter will be applied if applicable
rows_to_use = aggregate(x = rows_to_use$call_times,by= (list(rows_to_use$DispatchCodeAndSuffix)),median)
#Take the median of each dispatch code in the list
rows_to_use <- rows_to_use[order(-rows_to_use$x),]
#Order by largest to smallest median call time
rows_to_use <-head(rows_to_use,100)
#Take the top 100
x = c(rows_to_use$x)
y = c(rows_to_use$Group.1)
#Create vectors for bar plot
barchart(x, names.arg=y)
#Plot barchart
print(2)
解决方案
没关系,如果其他人有这个问题,我就解决了,只需使用 colClasses 指定 read.csv 中列的数据类型,例如
df <-read.csv(file="C:/Users/GIGNWI_Ar208671/Documents/R/Projects/CallTimes/call_times/data/risks_codes_descriptions.csv",header=TRUE,colClasses=c("DispatchCodeAndSuffix"="character"))
推荐阅读
- css - AWS放大的重复线性梯度错误
- mysql - 用未来年份创建 @X 行
- django - Django:通过字段关系注释用户的回复计数,以及查询优化
- .net - 异常后在调试器中继续代码
- c# - Ubuntu 上 C# 的 VSCode 自动补全
- ruby-on-rails - 在 ubuntu 20.04 上运行 rake db:create 时出现错误“LoadError:无法加载此类文件 -- 赛璐珞/当前”
- c# - 如何使用 WMI c# Windows 窗体刷新设备列表
- antlr - TestRig / grun 在解析示例文件时卡住了
- apache-camel - 消息在执行完成后写入队列并且生产者已停止
- node.js - 为什么我非常基本的 node.js 端点超时?