2015-05-11 47 views
1

我有一個包含一些向量的列表。例如,「myList中」看起來是這樣的:將data.frame添加到包含向量的現有列表中

myList 

$mean 
[1] 2 3 4 5 6 7 8 9 0 10 

$sd 
[1] 3 5 3 

我想一個新的data.frame「數據」添加到這個列表存在,使得「myList中」有三個要素:myList$meanmyList$sdmyList$data

這怎麼辦?

+0

嘗試'$ myList中數據< - data' – zx8754

回答

2

嘗試

myList$data <- df 

其中df是你的數據幀

2

試試這個例子:

#existing list 
myList <- list(mean=c(1:10), 
       sd=c(11:15)) 

#new dataframe 
df1 <- data.frame(x=1:10, 
        y=11:20) 
#add dataframe 
myList$df <- df1 

#result 
str(myList) 

#output 
# List of 3 
# $ mean: int [1:10] 1 2 3 4 5 6 7 8 9 10 
# $ sd : int [1:5] 11 12 13 14 15 
# $ df :'data.frame': 10 obs. of 2 variables: 
# ..$ x: int [1:10] 1 2 3 4 5 6 7 8 9 10 
# ..$ y: int [1:10] 11 12 13 14 15 16 17 18 19 20 
相關問題