2014-02-26 154 views
1

所以,我想從我的數據中刪除單個單元格。問題是,一個正常的功能不起作用:如何刪除單個單元格?

data[-1,] 
data[-1,-1] 
data$x = NULL 

所以這是我主要的代碼看起來是這樣的:

data_rd <- data_rd[-1,] ## I could delete one row but can't the next one. 

## Create an empty matrix 
name_cols <- paste0("F", rep(1:20, each = 4), "_", 1:4) 
name_columns <- c("Description", name_cols) 

mat_master_EOD <- matrix(0, nrow = length(data_rd[,1]),ncol = 81) 
colnames(mat_master_EOD) <- name_columns 
rownames(mat_master_EOD) <- data_rd[,1] 

,我想刪除單元格: http://imageshack.com/a/img32/6227/hy0s.jpg

我用rbind.fill函數來分組一些數據文件,這可能是我無法刪除這個cell的原因湖

編輯: 這只是我能爲你做:

dput(data_rd[1:3, 1:3]) 
structure(list(X = c("Accession", "ZZ_FGCZCont0025", "ZZ_FGCZCont0099" 
), X.1 = structure(c(29L, 22L, 20L), .Label = c("", "1", "10", 
"11", "12", "13", "14", "15", "16", "17", "18", "19", "2", "20", 
"21", "23", "25", "27", "28", "29", "3", "34", "4", "5", "6", 
"7", "8", "9", "Peptide count", "22", "24", "26", "30", "31", 
"32", "33", "35", "36", "37", "40", "41", "45", "46", "50", "55", 
"63", "73", "38", "48", "56", "68", "82", "39", "42", "43", "44", 
"58", "67", "76", "90", "59", "49", "54", "71", "65", "51", "53", 
"57", "61", "64", "74", "75", "47", "52", "60", "72", "69", "70", 
"62"), class = "factor"), X.2 = structure(c(23L, 9L, 15L), .Label = c("", 
"0", "1", "10", "11", "12", "13", "14", "15", "16", "17", "18", 
"19", "2", "28", "3", "4", "5", "6", "7", "8", "9", "Peptides used for quantitation", 
"20", "21", "22", "23", "24", "25", "26", "27", "29", "30", "33", 
"37", "39", "41", "45", "46", "49", "32", "34", "35", "36", "44", 
"68", "40", "43", "47", "66", "88", "42", "59", "58", "52", "71", 
"31", "38", "51", "48", "50", "62"), class = "factor")), .Names = c("X", 
"X.1", "X.2"), row.names = 2:4, class = "data.frame") 

併爲新創建的矩陣:

> dput(mat_master_EOD[1:10, 1:10]) 
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(10L, 
10L), .Dimnames = list(c("Accession", "ZZ_FGCZCont0025", "ZZ_FGCZCont0099", 
"ZZ_FGCZCont0126", "ZZ_FGCZCont0146", "AT1G19570", "ZZ_FGCZCont0158", 
"AT5G38480", "ZZ_FGCZCont0050", "AT1G07370"), c("Description", 
"F1_1", "F1_2", "F1_3", "F1_4", "F2_1", "F2_2", "F2_3", "F2_4", 
"F3_1"))) 
+0

你能輸(數據[1:10,1:10])嗎? – BrodieG

+0

完成。我想通過設置它的名稱來輕鬆訪問第一列。 –

+0

「刪除單元格」是什麼意思?永遠不能刪除矩陣中的單元格,只能刪除其內容。 –

回答

1

我到達這裏,但是這是你」再試圖獲得:

 Accession Peptide count Peptides used for quantitation 
3 ZZ_FGCZCont0025   34        15 
4 ZZ_FGCZCont0099   29        28 

如果是的話,你可以這樣做:

setNames(data_rd[-1,], sapply(data_rd[1, ], as.character)) 

請注意,您的Peptide...列是因素,這對數字列非常混淆。你應該考慮使用類似read.csv(file="blahblah", header=TRUE)的東西來重新導入數據,我認爲這些數據可以解決大部分問題。

+0

創建矩陣後,它仍然給我這個空單元格..我會嘗試明天玩,因爲我現在必須離開。 –

+0

我用這些函數來加載文件:tbl = list.files(pattern =「*。csv」) list_of_data = lapply(tbl,read.csv) –