I tried to assign a data frame as an element to a list, but after the assignment I found that the data frame has been changed to a list with values from the first column of the开发者_StackOverflow中文版 data frame.
For example the following code :
dfm <- data.frame(x=1:2, y=3:4)
print(dfm)
l <- list()
l['Key'] <- dfm
print(l)
gives the output:
x y
1 1 3
2 2 4
$Key
[1] 1 2
Is there a way to keep the data frame the way it is in a list ?
It would benefit you to pay attention to the warning message:
Warning message:
In l["Key"] <- dfm :
number of items to replace is not a multiple of replacement length
You want to use [[
instead of [
(read ?Extract
to understand why):
l[['Key']] <- dfm
精彩评论