2017-07-18 66 views
0

我是新來這個網站很抱歉,如果這個職位是蹩腳的。使數據幀中的一個新的變量/列具有一定的質量從現有的數據幀

我正在從一個海量數據文件中工作,所以我將給出一個它看起來像here的小例子。

在這個數據文件中,「plate」列有三個值:1,2和3.我試圖創建三個新列,每列具有特定行的「Abs.530nm」值if它包含了相應的車牌號碼(例如從板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

您正在使用'基地R'語法與'dplyr'一起。我認爲你需要'data.row%>%GROUP_BY(箱,板=因子(板,水平= 1:3))%>%的過濾器(name.start == 1)''的部分subset'目前尚不清楚。你的意思是'name.start == 1' – akrun

回答

0

data.table包是大數據集的速度非常快,這是很容易的子集像你描述。

我建議,而不是創建三個獨立Abs.530nm列,你根本篩選數據幀三種不同的方式,爲每個因子水平。這比在「ABS.530nm板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)] 
相關問題