Questions tagged «r»

R是一种免费的开源编程语言和软件环境,用于统计计算,生物信息学,可视化和通用计算。请提供最少且可复制的示例以及所需的输出。使用`dput()`作为数据,并通过`library()`调用指定所有非基本包。不要为数据或代码嵌入图片,而应使用缩进的代码块。对于统计相关的问题,请使用https://stats.stackexchange.com。

1
子集数据框时选择了未定义的列
我有一个数据框,str(data)以显示有关我的数据框的更多信息,结果如下: > str(data) 'data.frame': 153 obs. of 6 variables: $ Ozone : int 41 36 12 18 NA 28 23 19 8 NA ... $ Solar.R: int 190 118 149 313 NA NA 299 99 19 194 ... $ Wind : num 7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 …
79 r  dataframe  subset 

7
从日期中提取年份
如何从变量中删除第一个元素,尤其是在此变量具有特殊字符的情况下。例如,我有以下专栏: Date 01/01/2009 01/01/2010 01/01/2011 01/01/2012 我需要有一个新的列,如下所示: Date 2009 2010 2011 2012
79 r  date 

4
错误:找不到函数“%>%”
我正在R中运行一个示例,逐步执行这些步骤,到目前为止,一切正常,除了此代码会产生错误: words <- dtm %>% as.matrix %>% colnames %>% (function(x) x[nchar(x) < 20]) 错误:找不到函数“%>%” 我不知道使用此特殊运算符的好处是什么 %>%,任何反馈都很好。
79 r  dplyr  magrittr 

7
具有对数刻度和自定义间隔的直方图
我正在尝试用R的对数刻度生成R的直方图。目前,我正在: hist(mydata$V3, breaks=c(0,1,2,3,4,5,25)) 这给了我一个直方图,但是0到1之间的密度是如此之大(相差一百万左右),以至于您几乎无法分辨出其他任何条形。 然后我尝试做: mydata_hist <- hist(mydata$V3, breaks=c(0,1,2,3,4,5,25), plot=FALSE) plot(rpd_hist$counts, log="xy", pch=20, col="blue") 它为我提供了所需的内容,但底部显示的是值1-6,而不是0、1、2、3、4、5、25。它还将数据显示为点而不是条。barplot可以,但是我没有任何底轴。
79 r  histogram  logarithm 

1
错误:找不到功能“单位”
尝试修改主题设置时,此简单代码给出以下错误: library(ggplot2) theme_nogrid <- theme_set(theme_update( plot.margin=unit(c(.25, .25, .25, .25), "in"),)) Error in do.call(theme, list(...)) : could not find function "unit" R给我任何使用'unit'的元素的错误。其他任何不称为“单位”的设置都可以正常工作。我正在运行R v.2.15.2(64位Windows)。 我在网上广泛搜索了此问题,却一无所获。感谢您对问题的任何建议。
78 r  ggplot2 

7
从数据框中的标签获取列索引
假设我们有以下数据框: > df A B C 1 1 2 3 2 4 5 6 3 7 8 9 我们可以从其索引中选择列“ B”: > df[,2] [1] 2 5 8 有没有办法从列标签('B')中获取索引(2)?
78 r 


17
Linux中的R可使用哪些IDE?[关闭]
关闭。此问题不符合堆栈溢出准则。它当前不接受答案。 想改善这个问题吗?更新问题,使其成为Stack Overflow的主题。 7年前关闭。 改善这个问题 在Linux中,R有哪些好的IDE? 我已经尝试过Rcmdr和Eclipse,但是它们似乎都没有Windows中的Tinn-R一样的可用性。还有其他选择吗?
78 r  ide 

7
错误:安装R相关软件包时未找到gdal-config,但已安装gdal
请指出我缺少的一点: openSUSE 11.3 xx@linux-y3pi:~/Desktop/R> sudo R CMD INSTALL rgdal_0.7-12.tar.gz root's password: * installing to library ‘/usr/lib64/R/library’ * installing *source* package ‘rgdal’ ... ** package ‘rgdal’ successfully unpacked and MD5 sums checked configure: gdal-config: gdal-config checking gdal-config usability... ./configure: line 1353: gdal-config: command not found no Error: gdal-config not found The …
78 linux  r  installation  gdal 

2
如何在正则表达式中处理\ ^ $。?* | +()[{等特殊字符?
我想匹配一个正则表达式特殊字符,\^$.?*|+()[{。我试过了: x <- "a[b" grepl("[", x) ## Error: invalid regular expression '[', reason 'Missing ']'' (相当于stringr::str_detect(x, "[")或stringi::stri_detect_regex(x, "[")。) 将值加倍以使其无法逸出: grepl("[[", x) ## Error: invalid regular expression '[[', reason 'Missing ']'' 也不使用反斜杠: grepl("\[", x) ## Error: '\[' is an unrecognized escape in character string starting ""\[" 如何匹配特殊字符? 在一些古老而又写得很好的问题中,对此有一些特殊情况,以至于像它的副本一样厚脸皮地关闭: R正则表达式 中的转义符如何在R中转义问号? 在正则表达式中转义管道(“ …
78 regex  r  r-faq 

6
R-如何在IF语句中测试字符(0)
我认为这非常简单,但是我似乎找不到答案。 我正在编写IF语句,但是测试是对象是否返回character(0)值。我不确定character(0)声明中的处理方式。 假设Test <- character(0)或一个值: if (identical(Pols4,character(0))) { print('Empty') } else { print('Not Empty') } 它似乎仍然不起作用.....
78 r  if-statement 

5
过滤出data.table中的重复/非唯一行
编辑2019: 在2016年11月进行更改之前,曾问过这个问题data.table,有关当前方法和以前的方法,请参见下面可接受的答案。 我有一个data.table约250万行的表。有两列。我想删除在两列中都重复的任何行。以前对于data.frame我会这样做: df -> unique(df[,c('V1', 'V2')])但这对data.table不起作用。我已经尝试过,unique(df[,c(V1,V2), with=FALSE])但是它似乎仍然只对data.table的键进行操作,而不是对整个行进行操作。 有什么建议么? 欢呼声,戴维 例 >dt V1 V2 [1,] A B [2,] A C [3,] A D [4,] A B [5,] B A [6,] C D [7,] C D [8,] E F [9,] G G [10,] A B 在上面的data.table中,其中V2的表键是,仅删除行4,7和10。 > dput(dt) structure(list(V1 = c("B", …

4
多个变量的unique()
我在R中有以下数据框: > str(df) 'data.frame': 545227 obs. of 15 variables: $ ykod : int 93 93 93 93 93 93 93 93 93 93 ... $ yad : Factor w/ 42 levels "BAKUGAN","BARBIE",..: 30 30 30 30 30 30 30 30 30 30 ... $ per : Factor w/ 3 levels …
77 r  unique 

8
闪亮的4个小文本输入框并排
我有一个闪亮的服务器版本0.4.0,我想有4个小的textInput框看起来像这样: x-min x-max y-min y-max [...] [...] [...] [...] 他们现在看起来像这样: x-min [...................] x-max [...................] y-min [...................] y-max [...................] 使用此代码: textInput(inputId="xlimitsmin", label="x-min", value = 0.0), textInput(inputId="xlimitsmax", label="x-max", value = 0.5), textInput(inputId="ylimitsmin", label="y-min", value = 0.5), textInput(inputId="ylimitsmax", label="y-max", value = 1.0), 任何想法如何实现这一目标? 编辑:我已经成功更改了代码中其他地方的内容: <style type="text/css">select#yaxis4 { height: 280px; width: 500px; }</style> [... …
77 r  shiny 

4
提取回归系数值
对于一些调查药物利用情况的时间序列数据,我有一个回归模型。目的是使样条曲线适合时间序列并计算95%CI等。模型如下: id <- ts(1:length(drug$Date)) a1 <- ts(drug$Rate) a2 <- lag(a1-1) tg <- ts.union(a1,id,a2) mg <-lm (a1~a2+bs(id,df=df1),data=tg) 的摘要输出mg为: Call: lm(formula = a1 ~ a2 + bs(id, df = df1), data = tg) Residuals: Min 1Q Median 3Q Max -0.31617 -0.11711 -0.02897 0.12330 0.40442 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) …
77 r  regression  lm 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.