Error in xtfrm.data.frame(x) : cannot xtfrm data frames

在《R语言实战》第七章第五节,代码清单7-17中,作者进行了如下代码运行:

出现如下报错:

source("http://www.statmethods.net/RiA/wmc.txt")

> states <- data.frame(state.region, state.x77)

> wmc(Illiteracy ~ state.region, data=states, method="holm")

Error in xtfrm.data.frame(x) : cannot xtfrm data frames

可以通过修改source地址解决

source("http://mp.ituring.com.cn/files/RiA3/rfiles/wmc.R")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The R language is widely used by statisticians for data analysis, and the popularity of R programming has therefore increased substantially in recent years. The emerging Internet of Things (IoT) gathers increasing amounts of data that can be analyzed to gain useful insights into trends. R for Data Analysis in easy steps has an easy-to-follow style that will appeal to anyone who wants to produce graphic visualizations to gain insights from gathered data. R for Data Analysis in easy steps begins by explaining core programming principles of the R programming language, which stores data in “vectors” from which simple graphs can be plotted. Next, the book describes how to create “matrices” to store and manipulate data from which graphs can be plotted to provide better insights. This book then demonstrates how to create “data frames” from imported data sets, and how to employ the “Grammar of Graphics” to produce advanced visualizations that can best illustrate useful insights from your data. R for Data Analysis in easy steps contains separate chapters on the major features of the R programming language. There are complete example programs that demonstrate how to create Line graphs, Bar charts, Histograms, Scatter graphs, Box plots, and more. The code for each R script is listed, together with screenshots that illustrate the actual output when that script has been executed. The free, downloadable example R code is provided for clearer understanding. By the end of this book you will have gained a sound understanding of R programming, and be able to write your own scripts that can be executed to produce graphic visualizations for data analysis. You need have no previous knowledge of any programming language, so it's ideal for the newcomer to computer programming. Table of Contents Chapter 1 Getting Started Chapter 2 Storing Values Chapter 3 Performing Operations Chapter 4 Testing Conditions Chapter 5 Employing Functions Chapter 6 Building Matrices Chapter 7 Constructing Data Frames Chapter 8 Producing Quick Plots Chapter 9 Storytelling With Data Chapter 10 Plotting Perfection
### 回答1: 这个错误提示是因为在使用xtfrm函数时,不能对数据框进行转换。xtfrm函数是用于对数据进行排序和比较的,但是数据框不支持这种操作。如果需要对数据框进行排序或比较,可以使用sort函数或者order函数。 ### 回答2: 在R编程中,当我们使用xtfrm函数对数据进行排序时,可能会遇到“in xtfrm.data.frame(x) : cannot xtfrm data frames”的错误提示。 这个错误提示的意思是xtfrm函数无法对数据框进行排序,因为它们包含多种数据类型,如字符、数值和逻辑等。xtfrm函数只能对具有单一数据类型的向量进行排序。 为解决这个问题,我们可以将数据框转换为单一数据类型的向量,例如将每列的数据合并到一个向量中,然后使用该向量进行排序。这种方法可以使用unlist函数。 另一种解决方法是使用dplyr或tidyr包中的函数进行数据转换和排序。这些包提供了丰富的数据处理功能,可以轻松地处理各种数据类型,避免了xtfrm函数对数据框的限制。 最后,我们需要注意,在使用xtfrm函数对数据框进行排序时,如果数据框中的列具有不同的数据类型,则结果可能会不正确。因此,在进行排序时,应确保数据框中的所有列具有相同的数据类型。 ### 回答3: xtfrm.data.frame(x) : cannot xtfrm data frames这个错误信息是在处理R语言的数据分析时常见的错误。一般情况下,如果在对一个数据框进行排序时出现这个错误信息,那么原因可能是数据框中存在非数字类型的变量,如字符型、逻辑型或因子型变量。 在进行排序操作时,R语言需要对数据框的每一列进行比较,以决定如何排序。然而,非数字型变量无法比较,因此会出现错误信息。 要解决这个问题,可以用以下两种方式: 1. 删除非数字型变量:在进行排序操作前,将非数字型变量删除,只对数字型变量进行排序。可以使用函数select()来选择需要的变量。 例如: library(dplyr) data %>% select_if(is.numeric) %>% arrange(desc(x)) 这个例子中,用select_if函数选择了数值型变量,并按照变量x倒序排序。 2. 将非数字型变量转换为数字型变量:将非数字型变量转换为数字型变量后,可以继续对数据框进行排序操作。可以使用函数as.numeric()将字符型变量转换为数字型变量,使用函数as.integer()将逻辑型或因子型变量转换为整数型。 例如: data$y <- as.numeric(data$y) data %>% arrange(desc(x), y) 这个例子中,将变量y由字符型转换为数字型后,对x和y进行降序排列。 总之,在进行数据框的排序操作前,一定要注意数据框中的变量类型,以免出现xtfrm data frames的错误信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值