2017-10-09 90 views
0

我想通過使用包提供的示例數據來學習名爲TropFishR的包。包中提供的數據同時包含矢量和矩陣。我如何安排我的數據,像這樣在同一個數據包中的矩陣和向量R

> data(alba) 
> print(alba) 
$sample.no 
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 

$midLengths 
[1] 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 

$dates 
[1] "1976-04-17" "1976-07-02" "1976-09-19" "1976-12-15" "1977-02-18" "1977- 
04-30" 
[7] "1977-06-24" 

$catch 
    1976.29315068493 1976.50136986301 1976.71780821918 1976.95616438356 
    1977.13150684931 
[1,]    0    0    0    2     
0 
[2,]    0    1    9    1     
1 
[3,]    0    1    34    3     
0 
[4,]    1    0    96    3     
0 
[5,]    1    1    68    4     
2 
[6,]    1    0    50    21     

attr(,"class") 
[1] "lfq" 
+0

可以請你更具體與您的問題,你的目標是什麼? –

+0

創建一個數據,包括這樣的向量和矩陣。 –

+0

你需要一個數據框嗎?我仍然不清楚你需要什麼 –

回答

1

您可以從下面的代碼獲得的想法...

### Data generte..... 
sample.no<-seq(1,14) 
dates<-c("1976-04-17","1976-07-02","1976-09-19","1976-12-15","1977-02-18", 
"1977-04-30","1977-06-24") 

catch<-matrix(rbinom(25,20,0.5),5,5) 
colnames(catch)<-c(10,20,30,40,50) 


### Including within list named 'Yourdata' 
Yourdata<-list(sample.no,dates,catch) 
names(Yourdata)<-c("sample.no","dates","catch") 
Yourdata 

輸出:

$sample.no 
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 

$dates 
[1] "1976-04-17" "1976-07-02" "1976-09-19" "1976-12-15" "1977-02-18" 
[6] "1977-04-30" "1977-06-24" 

$catch 
    10 20 30 40 50 
[1,] 11 8 11 8 9 
[2,] 10 11 12 8 9 
[3,] 9 8 8 8 9 
[4,] 12 12 11 10 11 
[5,] 11 10 9 9 15 
+0

這就是我一直在尋找的。感謝你的回答。 –

+0

Yahya作爲一個手勢,請upvote並接受答案 –