在现有数据框架中以一定质量在数据框中创建新的变量/列

时间:2017-07-18 17:35:29

标签: r

我是这个网站的新手很抱歉,如果这篇文章很糟糕。

我正在使用大量数据文件,因此我将举例说明here的内容。

在此数据文件中,"铭牌" column有三个值:1,2和3.我试图创建三个新列,每列都有" Abs.530nm"特定行的值,如果它包含相应的板号(例如将板1的吸光度值分成新的列等)

这就是我试图做的事情:

data.row$plate %<>% factor(levels = c("1","2","3"))

data.row %>%
 group_by(box, plate) %>%
 diff.tr.1.2 <- subset(plate, name.start <-"1", drop=FALSE) %>%


{.} ->data.tech

我收到了这个错误:

Error in subset(plate, name.start <- "1", drop = FALSE) : 
object 'plate' not found

有没有办法做我想做的事情?

1 个答案:

答案 0 :(得分:0)

对于大型数据集,data.table包非常快,并且很容易像您描述的那样进行子集化。

我建议您不要创建三个独立的Abs.530nm色谱柱,只需以三种不同的方式过滤数据帧,每个因子级别一个。这比在“ABS.530nm Plate 1”栏中引入NA值更清晰的解决方案

假设您的数据框名为df

require(data.table)
as.data.table(df)

#  plate == 1 is your "filter" selecting only rows where the plate is 1
#  by defines your grouping, in this case, by box, then by plate

output <- df[plate ==1, by= .(box,plate)]
相关问题