r - R中直方图的binwidth
问题描述
到目前为止,这是我的程序。我需要让用户接下来输入他们自己的 bindwidth,但我不知道该怎么做。
file.name <- readline('Please enter name and file location: ')
has.header <- readline('Does your data file contain a header (Y/N)? ')
if (has.header == 'Y')
{
file.df <- read.table( file = file.name, sep=',', header = TRUE)
}else
{
file.df <- read.table ( file = file.name, sep=',', header = FALSE)
}
cat('\n')
print(file.df)
cat('\n')
#Histogram
print(head(file.df))
column <- as.numeric(readline('What column do you want to graph (enter number)? '))
print(hist(file.df[ ,column]))
#New bin width
binsize <- readline("Enter a new bin width for your graph: ")
解决方案
binsize <- as.integer(readline("Enter a new bin width for your graph: "))
xt <- readline("Enter x axis title: ")
yt <- readline("Enter y axis title: ")
binwidth <- as.integer(nrow(file.df)/binsize))
hist(file.df[, column], breaks = binwidth, xlab = xt, ylab = yt)
推荐阅读
- reactjs - 用反应钩子形式反应电话输入2
- python - 基于概率分布中值的聚合
- android - 滚动很多时 RecyclerView.Adapter ClassCastException
- excel - 运行VBA代码后不同单元格中的Excel下拉列表
- pentaho - 尝试在 Pentaho v5.4 中公开报告时出现“报告验证失败”错误
- c++ - 'new' 和 'delete' 在 C++ 中被弃用了吗?
- java - Spring Boot 获取 application.properties (或其文件路径)的距离
- java - 无法在视频视图android中播放视频表单网址
- excel - Excel 的链接在 Powerpoint 中中断
- java - 在 Hybris 的 itemtype 中使用扩展