问题描述
我使用 WGCNA 包来分析共表达的基因。在这里,我尝试形成一个类似于将保存临床特征的表达数据的数据框。我使用以下代码:
traitData 表
| × |样品 | NoduleperPlant |
|- |- |- |
| 1 | 1021_verbena_rep_1 | 2 |
| 2 | 1021_verbena_rep_2 | 3 |
| 3 | 1021_verbena_rep_3 | 1 |
| 4 | 1021_campporegio_rep_1 | 2 |
| 5 | 1021_camporegio_rep_2 | 3 |
| 6 | 1021_camporegio_rep_3 | 4 |
| 7 | BL225C_camporegio_rep_1 | 5 |
| 8 | BL225C_camporegio_rep_2 | 4 |
| 9 | BL225C_camporegio_rep_3 | 1 |
表dfxpr(部分基因列于表中)
|FIELD1 |aacC-1|aacC4-1|aapJ-1|aapM-1|aapP-1|aapQ-1|aarF-1|
|------------------------------|------|-------|--- ---|------|------|------|------|
|X1021_verbena_rep_1 |42 |46 |12412 |935 |3354 |2876 |550 |
|X1021_verbena_rep_2 |52 |37 |11775 |946 |2970 |2824 |514 |
|X1021_verbena_rep_3 |12 |22 |5077 |397 |1462 |1228 |230 |
|X1021_campporegio_rep_1 |52 |71 |12983 |1454 |3408 |3248 |707 |
|X1021_campporegio_rep_2 |20 |65 |9240 |803 |2807 |3146 |445 |
|X1021_campporegio_rep_3 |28 |53 |11030 |1065 |3480 |3410 |582 |
|BL225C_campporegio_rep_1|29 |19 |6346 |375 |938 |768 |118 |
|BL225C_campporegio_rep_2|51 |62 |12938 |781 |1765 |1629 |291 |
|BL225C_campporegio_rep_3|52 |43 |6462 |504 |1120 |1091 |238 |
traitData = read.csv("NodulPerPlantTraitForLowGroup.csv"); #this csv file contains 3 columns as the first column is non-relevant information,second column contains the names of samples and the third column holds the values measured for the traits.
# remove columns that hold information I do not need.
allTraits = traitData[,-1];
allTraits = allTraits[,1:2];
# Form a data frame analogous to expression data that will hold the clinical traits.
lowNoduleSamples = rownames(dfxpr) #dfxpr is a data frame containing 9 observations (i.e. samples) and 6398 variables (i.e. genes)
traitRows = match(lowNoduleSamples,allTraits$sample); #here is the line i get wrong values as NAs while i kNow they all should match
datTraits = allTraits[traitRows,-1]; #then this lines result NAs too
rownames(datTraits) = allTraits[traitRows,1];
collectGarbage();
我该如何解决问题?
解决方法
我在这一行添加了“drop = FALSE”:datTraits = allTraits[traitRows,-1]
datTraits = allTraits[traitRows,-1,drop = FALSE]
我意识到我的 allTraits 只包含 2 列;当我删除第一列时,我只剩下一列,除非我添加 drop = FALSE 参数,否则 R 会将其转换为单个向量。