Tag: r faq

只读取有限的列数

任何人都可以告诉我如何阅读下面的数据,每年只有前6个月(7列),例如通过使用read.table() ? Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2009 -41 -27 -25 -31 -31 -39 -25 -15 -30 -27 -21 -25 2010 -41 -27 -25 -31 -31 -39 -25 -15 -30 -27 -21 -25 2011 -21 -27 -2 -6 -10 -32 -13 -12 -27 -30 -38 -29

错误:意外的符号/输入/字符串常量/数字常量/ SPECIAL在我的代码

我收到这些错误之一。 Error: unexpected symbol in "<my code>" Error: unexpected input in "<my code>" Error: unexpected string constant in "<my code>" Error: unexpected numeric constant in "<my code>" Error: unexpected SPECIAL in "<my code>" Error: unexpected '<some punctuation>' in "<my code>" Error: unexpected '<reserved word>' in "<my code>" 错误是什么意思,我该如何解决? 一些简单的例子,重现错误和常见的变种: aa ## Error: unexpected symbol in […]

在R中调试的一般建议

使用我写的R函数时出现错误: Warning messages: 1: glm.fit: algorithm did not converge 2: glm.fit: algorithm did not converge 我做了什么: 逐步完成功能 添加打印以查明错误发生在哪一行提示两个不应该使用glm.fit 。 他们是window()和save() 。 我的一般方法包括添加print和stop命令,逐行逐行扫描功能,直到找到异常。 然而,我不清楚使用这些技术的错误来自代码。 我甚至不确定代码中的哪些函数依赖于glm.fit 。 我如何去诊断这个问题?

<code>:object类型为'closure'的对象不是子集合

我终于能够弄清楚我的代码了。 它似乎工作正常,然后突然当我再次运行,我得到了以下错误信息: Error in url[i] = paste("http://en.wikipedia.org/wiki/", gsub(" ", "_", : object of type 'closure' is not subsettable 我不知道为什么,因为我没有改变我的代码。 请指教。 library(XML) library(plyr) names <- c("George Clooney", "Kevin Costner", "George Bush", "Amar Shanghavi") for(i in 1:length(names)) { url[i] = paste('http://en.wikipedia.org/wiki/', gsub(" ","_", names[i]) , sep="") # some parsing code }

当两行数据帧(rbind)有不同的列组合时,组合两个数据帧

是否有可能绑定两个没有相同的列的数据框? 我希望保留绑定后不匹配的列。

如何在运行中命名变量?

是否有可能在飞行中创建新的变量名称? 我想从列表中读取数据框到最后带有数字的新变量。 像orca1,orca2,orca3 … 如果我尝试类似的东西 paste("orca",i,sep="")=list_name[[i]] 我得到这个错误 target of assignment expands to non-language object 有没有其他的方法呢?