我有一个带有NA的数据框,我想用行方式替换NA
c1 = c(1,2,3,NA)
c2 = c(3,1,NA,3)
c3 = c(2,1,3,1)
df = data.frame(c1,c2,c3)
> df
c1 c2 c3
1 1 3 2
2 2 1 1
3 3 NA 3
4 NA 3 1
Run Code Online (Sandbox Code Playgroud)
以便
> df
c1 c2 c3
1 1 3 2
2 2 1 1
3 3 3 3
4 2 3 1
Run Code Online (Sandbox Code Playgroud) 如何以预先安装的数据warpbreaks为例隔离摘要中的重要性列(aov())...
> a<-summary(aov(breaks~wool*tension,data=warpbreaks))
> a
Df Sum Sq Mean Sq F value Pr(>F)
wool 1 451 450.7 3.765 0.058213 .
tension 2 2034 1017.1 8.498 0.000693 ***
wool:tension 2 1003 501.4 4.189 0.021044 *
Residuals 48 5745 119.7
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> somefunction(a)[,6]
1 .
2 ***
3 *
4
Run Code Online (Sandbox Code Playgroud) 我想在一个向量中添加每个元素,每个元素在另一个向量中,如下所示,但避免使用for循环.有一个简单的方法吗?
vadd <- function(vrow, vcol){
vmatrix <- matrix(nrow = length(vrow), ncol = length(vcol))
for(r in 1:length(vrow)){#rows
for(c in 1:length(vcol)){#columns
vmatrix[r, c] <- vrow[r] + vcol[c]
}
}
return(vmatrix)
}
a <- c(1:10)
b <- c(3:4)
vadd(a, b)
Run Code Online (Sandbox Code Playgroud)
布莱恩,真诚的
我正在处理一个大型数据集,我想查找所有站点共有的日期.
site <- c(1,1,1,2,2,2,2,3,3,4,4,4)
date <- c("4th Nov","5th Nov","6th Nov","5th Nov","6th Nov","7th Nov","8th Nov","5th Nov","6th Nov","6th Nov","7th Nov","8th Nov")
temperature <- c(3,5,7,3,6,8,5,3,5,7,8,9)
data <- data.frame(site,date,temperature)
common.dates(data)
[1] "6th Nov"
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.谢谢!