R程序中的错误太多

R程序中的错误太多,r,read.table,R,Read.table,我刚开始在本科第二学期学习R。这里有很多东西很难想象。我希望你能给我指出正确的方向 起初我不确定为什么require行给出了错误,然后我发现它们试图加载不在我的R安装中的包,所以我把它们放在了上面。我还发现,给我的数据要放在一个名为auto_mpg.txt的文件中。但是那一行之后的错误对我来说很难理解 你能帮我理解吗 R version 3.4.1 (2017-06-30) -- "Single Candle" Copyright (C) 2017 The R Foundation for St

我刚开始在本科第二学期学习R。这里有很多东西很难想象。我希望你能给我指出正确的方向

起初我不确定为什么require行给出了错误,然后我发现它们试图加载不在我的R安装中的包,所以我把它们放在了上面。我还发现,给我的数据要放在一个名为auto_mpg.txt的文件中。但是那一行之后的错误对我来说很难理解

你能帮我理解吗

R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Workspace loaded from ~/R/my_project/.RData]

> #################################################################
> #################  NIKITA TIWARI ############################
> #################################################################
> #################  DATA SUMMARY PJ1  ############################
> ##       mpg             cyl              wt           region     
> ##  Min.   : 9.00   Min.   :3.000   Min.   :1613   Min.   :1.000  
> ##  1st Qu.:17.50   1st Qu.:4.000   1st Qu.:2224   1st Qu.:1.000  
> ##  Median :23.00   Median :4.000   Median :2804   Median :1.000  
> ##  Mean   :23.51   Mean   :5.455   Mean   :2970   Mean   :1.573  
> ##  3rd Qu.:29.00   3rd Qu.:8.000   3rd Qu.:3608   3rd Qu.:2.000  
> ##  Max.   :46.60   Max.   :8.000   Max.   :5140   Max.   :3.000  
> ##                                                                
> ##             model    
> ##  ford pinto    :  6  
> ##  amc matador   :  5  
> ##  ford maverick :  5  
> ##  toyota corolla:  5  
> ##  amc gremlin   :  4  
> ##  amc hornet    :  4  
> ##  (Other)       :369
> #################################################################
> #################################################################
> 
> require(gridExtra) #given to me
Loading required package: gridExtra
Warning message:
package ‘gridExtra’ was built under R version 3.4.2 
> require(ggplot2) #given to me
Loading required package: ggplot2
Warning message:
package ‘ggplot2’ was built under R version 3.4.2 
> 
> 
> auto <- read.table("auto_mpg.txt", sep="\t", header = TRUE) #given to me
> head(auto)
            mpg.............cyl..............wt...........region
1 Min.   : 9.00   Min.   :3.000   Min.   :1613   Min.   :1.000  
2 1st Qu.:17.50   1st Qu.:4.000   1st Qu.:2224   1st Qu.:1.000  
3 Median :23.00   Median :4.000   Median :2804   Median :1.000  
4 Mean   :23.51   Mean   :5.455   Mean   :2970   Mean   :1.573  
5 3rd Qu.:29.00   3rd Qu.:8.000   3rd Qu.:3608   3rd Qu.:2.000  
6 Max.   :46.60   Max.   :8.000   Max.   :5140   Max.   :3.000  
> summary(auto) #given to me
                                     mpg.............cyl..............wt...........region
 1st Qu.:17.50   1st Qu.:4.000   1st Qu.:2224   1st Qu.:1.000  :1                        
 3rd Qu.:29.00   3rd Qu.:8.000   3rd Qu.:3608   3rd Qu.:2.000  :1                        
 Max.   :46.60   Max.   :8.000   Max.   :5140   Max.   :3.000  :1                        
 Mean   :23.51   Mean   :5.455   Mean   :2970   Mean   :1.573  :1                        
 Median :23.00   Median :4.000   Median :2804   Median :1.000  :1                        
 Min.   : 9.00   Min.   :3.000   Min.   :1613   Min.   :1.000  :1                        
> 
> 
> auto$cyl <- as.factor(auto$cyl)
Error in `$<-.data.frame`(`*tmp*`, cyl, value = integer(0)) : 
  replacement has 0 rows, data has 6
> auto$region <- as.factor(auto$region)
Error in `$<-.data.frame`(`*tmp*`, region, value = integer(0)) : 
  replacement has 0 rows, data has 6
> auto$cyl[auto$cyl == 1] <- "USA"
Error in `$<-.data.frame`(`*tmp*`, cyl, value = character(0)) : 
  replacement has 0 rows, data has 6
> auto$cyl[auto$cyl == 2] <- "EUR"
Error in `$<-.data.frame`(`*tmp*`, cyl, value = character(0)) : 
  replacement has 0 rows, data has 6
> auto$cyl[auto$cyl == 3] <- "ASIA"
Error in `$<-.data.frame`(`*tmp*`, cyl, value = character(0)) : 
  replacement has 0 rows, data has 6
> auto$region[auto$region == 1] <- "USA"
Error in `$<-.data.frame`(`*tmp*`, region, value = character(0)) : 
  replacement has 0 rows, data has 6
> auto$region[auto$region == 2] <- "EUR"
Error in `$<-.data.frame`(`*tmp*`, region, value = character(0)) : 
  replacement has 0 rows, data has 6
> auto$region[auto$region == 3] <- "ASIA"
Error in `$<-.data.frame`(`*tmp*`, region, value = character(0)) : 
  replacement has 0 rows, data has 6
> 
> auto$cyl <- factor(auto$cyl, levels=c("USA","EUR","ASIA"))
Error in `$<-.data.frame`(`*tmp*`, cyl, value = integer(0)) : 
  replacement has 0 rows, data has 6
> auto$region <- factor(auto$region, levels=c("USA","EUR","ASIA"))
Error in `$<-.data.frame`(`*tmp*`, region, value = integer(0)) : 
  replacement has 0 rows, data has 6
> summary(auto)
                                     mpg.............cyl..............wt...........region
 1st Qu.:17.50   1st Qu.:4.000   1st Qu.:2224   1st Qu.:1.000  :1                        
 3rd Qu.:29.00   3rd Qu.:8.000   3rd Qu.:3608   3rd Qu.:2.000  :1                        
 Max.   :46.60   Max.   :8.000   Max.   :5140   Max.   :3.000  :1                        
 Mean   :23.51   Mean   :5.455   Mean   :2970   Mean   :1.573  :1                        
 Median :23.00   Median :4.000   Median :2804   Median :1.000  :1                        
 Min.   : 9.00   Min.   :3.000   Min.   :1613   Min.   :1.000  :1                        
> 
> ###################################################################
> # calculate the mean mpg for cars, broken out by the number of 
> # cylinders in the car.
> ###################################################################
> 
> 
> ###################################################################
> #Provide a description of what you notice above
> ###################################################################
> # write a line describing the purpose of the next code chunk
> ###################################################################
> 
> 
> ###################################################################
> #provide a dsecriptiojn of what you notice above
> ###################################################################
> # Histograms
> ###################################################################
> # the next chunk of code is creating bar graphs and filling them 
> # with either region or cyl , with count on the y axis and 
> # mpg on the x axis
> ###################################################################
> ggplot(auto, aes(x = mpg, y = count, fill = cyl)) + geom_bar()
Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.
Error in FUN(X[[i]], ...) : object 'count' not found
> ggplot(auto, aes(x = mpg, y = count, fill = region)) + geom_bar()
Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.
Error in FUN(X[[i]], ...) : object 'count' not found
> ###################################################################
> # provide a description of what you notice above
> ###################################################################
> # write a line describe the purpose of the next chunck of code
> ###################################################################
> b1 <- ggplot(auto, aes(x=cyl, fill=cyl)) + geom_bar()
> b2 <- ggplot(auto, aes(x=region, fill=region)) + geom_bar()
> ###################################################################
> # the above code is used to creat a specific bar graph and it's 
> # x axis is the same a the fill so that it is more clear
> ###################################################################
> # the next chunck of code is used to fill the graph with the bars
> ###################################################################
> b3 <- ggplot(auto, aes(x = cyl, fill = region)) + geom_bar(position = "fill")
> b4 <- ggplot(auto, aes(x = region, fill = cyl)) + geom_bar(position = "fill")
> grid.arrange(b1, b2 ,b3, b4, ncol= 4)
Error in FUN(X[[i]], ...) : object 'cyl' not found
> ###################################################################
> # provide a description of what you notice above
> ###################################################################
> # the code below is going to make box plots of the data
> ###################################################################
> bp1 <- ggplot ( auto, aes(x = cyl, y = mpg, fill = cyl)) + geom_boxplot()
> bp2 <- ggplot ( auto, aes(x = region, y = mpg, fill = region)) + geom_boxplot()
> grid.arrange(bp1, bp2, ncol = 2)
Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.
Error in FUN(X[[i]], ...) : object 'cyl' not found
> ###################################################################
> # provide a description of what you notice above
> ###################################################################
> # the code below is going to make box plots of the data spilt into
> # 3, 4, ,5, 6, 8 data with mpg being y axis, region being x axis
> # and region being the fill
> ###################################################################
> 
> 
> 
> 
> ###################################################################
> # provide a description of what you notice above
> ###################################################################
> # the code below is going to a jitter plot so basically its just a 
> # lot dots on a graph
> ###################################################################
> jp1 <- ggplot ( auto, aes(x = wt, y = mpg, fill = cyl)) + geom_jitter()
> jp2 <- ggplot ( auto, aes(x = wt, y = mpg, fill = region)) + geom_jitter()
> grid.arrange(jp1, jp2, ncol = 2)
Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.
Error in FUN(X[[i]], ...) : object 'wt' not found
> ###################################################################
> # provide a description of what you notice above
> ###################################################################
> # the code below is going to a jitter plot but separate the graphs
> # into the different regions and only that region shows up on the
> # graph 
> ###################################################################
> fg1 <- ggplot ( auto, aes(x = wt, y = mpg, fill = cyl)) + geom_jitter()
> + facet_grid(region)
Error in facet_grid(region) : object 'region' not found
> fg1
Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.
Error in FUN(X[[i]], ...) : object 'wt' not found
> 
> 
> ###################################################################
> # provide a description of what you notice above
> ###################################################################
> # the code below is going to a jitter plot but separate the graphs
> # into the different regions and into different cyl and only that 
> # cyl and that region show up in that graph
> ###################################################################
> 
R版本3.4.1(2017-06-30)-“单根蜡烛”
版权所有(C)2017统计计算基础
平台:x86_64-w64-mingw32/x64(64位)
R是免费软件,绝对没有保修。
在某些条件下,欢迎您重新分发。
键入“license()”或“license()”以获取分发详细信息。
R是一个有许多贡献者的协作项目。
键入“contributors()”以获取详细信息和
“引文()”介绍如何在出版物中引用R或R软件包。
对于某些演示,键入“demo()”;对于联机帮助,键入“help()”;或者
“help.start()”用于HTML浏览器界面的帮助。
键入“q()”退出R。
[从~/R/my_project/.RData加载的工作区]
> #################################################################
>尼基塔·蒂瓦里############################
> #################################################################
>数据汇总PJ1############################
>##mpg气缸wt区域
>##分钟:9.00分钟:3.000分钟:1613分钟:1.000
>##第一区:17.50第一区:4.000第一区:2224第一区:1.000
>##中位数:23.00中位数:4.000中位数:2804中位数:1.000
>##平均数:23.51平均数:5.455平均数:2970平均数:1.573
>##三区:29.00三区:8.000三区:3608三区:2.000
>#最大值:46.60最大值:8.000最大值:5140最大值:3.000
> ##                                                                
>##模型
>福特平托:6
>##amc斗牛士:5
>##福特特立独行:5
>丰田花冠:5
>##amc小精灵:4
>##amc大黄蜂队:4
>##(其他):369
> #################################################################
> #################################################################
> 
>要求(额外)给我
加载所需包:gridExtra
警告信息:
“gridExtra”包是在R版本3.4.2下构建的
>要求(ggplot2)#交给我
加载所需包:ggplot2
警告信息:
包“ggplot2”是在R版本3.4.2下构建的
> 
> 
>自动头(自动)
mpg…………气缸…………重量…………区域
1分钟:9.00分钟:3.000分钟:1613分钟:1.000
2第一区:17.50第一区:4.000第一区:2224第一区:1.000
3中位数:23.00中位数:4.000中位数:2804中位数:1.000
4平均值:23.51平均值:5.455平均值:2970平均值:1.573
5第三区:29.00第三区:8.000第三区:3608第三区:2.000
6最大:46.60最大:8.000最大:5140最大:3.000
>摘要(自动)#交给我
mpg…………气缸…………重量…………区域
第一区:17.50第一区:4.000第一区:2224第一区:1.000:1
第三区:29.00第三区:8.000第三区:3608第三区:2.000:1
最大值:46.60最大值:8.000最大值:5140最大值:3.000:1
平均数:23.51平均数:5.455平均数:2970平均数:1.573:1
中位数:23.00中位数:4.000中位数:2804中位数:1.000:1
分钟:9.00分钟:3.000分钟:1613分钟:1.000:1
> 
> 
>auto$cyl#提供您在上面注意到的内容的描述
> ###################################################################
>#写一行描述下一个代码块的用途
> ###################################################################
> 
> 
> ###################################################################
>#提供一份你在上面注意到的情况的描述
> ###################################################################
>#直方图
> ###################################################################
>#下一段代码是创建条形图并填充它们
>#具有区域或圆柱体,y轴上具有计数,且
>#x轴上的mpg
> ###################################################################
>ggplot(自动,aes(x=mpg,y=count,fill=cyl))+geom_-bar()
不知道如何为tbl_df/tbl/data.frame类型的对象自动拾取比例。默认为连续。
FUN(X[[i]],…)中出错:未找到对象“count”
>ggplot(自动,aes(x=mpg,y=count,fill=region))+geom_bar()
不知道如何为tbl_df/tbl/data.frame类型的对象自动拾取比例。默认为连续。
FUN(X[[i]],…)中出错:未找到对象“count”
> ###################################################################
>#请描述您在上面注意到的内容
> ###################################################################
>#写一行描述下一段代码的目的
> ###################################################################
>b1 b2###################################################################
>#上述代码用于创建特定的条形图,并且
>#x轴与填充相同,因此更清晰
> ###################################################################
>#下一段代码用于用条形图填充图形
> ###################################################################
>b3 b4网格排列(b1、b2、b3、b4,ncol=4)
FUN(X[[i]],…)中出错:未找到对象“cyl”
> ###################################################################
>#提供以下说明: