我有一个数据集,其中包含一些我想用NA替换的非引用数据。在下面的示例中,如果列rep1到rep4中的数据与ID列中的某个值不匹配,我希望将该值替换为NA。在本例中,x、y和z的值没有列在ID列中,因此应该替换它们。 这是我之前问过的一个有点类似的问题:If data present, replace with data from another column based on row ID 我认为解决方案将类似于上一个问题中给出的解决方案,但是我不知道如何修改第二部分~ value[match(., ID)],以便为ID列中未列出的值返回NA。 df %>% mutate_at(var
我很难用不成对的t检验和聚合函数。
示例
dd<-data.frame(names=c("1st","1st","1st","1st","2nd","2nd","2nd","2nd"),a=c(11,12,13,14,2.1,2.2,2.3,2.4),b=c(3.1,3.2,3.3,3.4,3.1,3.2,3.3,3.4))
dd
# Compare all the values in the "a" column that match wit
我要删除所有具有零或NAs的行。在下面的代码中,我选择数值变量,然后过滤出0。这里的问题是,在最终的输出中,它不返回字符变量和数字变量。
df <- read.table(header = TRUE, text =
"x y z
a 1 2
b 0 3
c 1 NA
d 0 NA
")
df %>% select_if(is.numeric) %>% filter(rowSums(., na.rm = T)!=0)
我有一个数据框,其中包含分组的名称,如下所示:
df <- data.frame(group = rep(letters[1:2], each=2),
name = LETTERS[1:4])
> df
group name
1 a A
2 a B
3 b C
4 b D
我想将其转换为一个以组名称为关键字并包含名称的列表。输出示例:
df_out <- list(a=c('A', 'B'),
b=c('C'
我有一个这样的数据帧:
experiment iter results
A 1 30.0
A 2 23.0
A 3 33.3
B 1 313.0
B 2 323.0
B 3 350.0
....
有没有办法通过应用带条件的函数来计算结果。在上面的示例中,该条件是特定实验的所有迭代。
A sum of results (30 + 23, + 33.3)
B sum of results (313 + 323 + 350
我有一个如下的数据框架:
DF<-data.frame(a=c(1,1,1,2,2,2,3,3,4,4),b=c(43,23,45,65,43,23,65,76,87,4))
a b
1 43
1 23
1 45
2 65
2 43
2 23
3 65
3 76
4 87
4 4
我想像这样设置一个标志:
a b flag
1 43 A
1 23 B
1 45 C
2 65 A
2 43 B
2 23 C
3 65 A
3 76 B
4 87 A
4 4 B
我怎样才能在R中完成这个任务呢?
我的职能是:
coeff_var <- function(data_stand) {
percvar <- (sd(data_stand)/mean(data_stand)*100)
return(percvar)
}
and I want to calculate multiple columns at a time. I have tried:
lapply(data_stand, coeff_var(data_stand))
apply(data_stand,2, coeff_var(data_stand))
summarise(data, data_coe