0
>str(testdata[1])

 List of 1
 $ :'data.frame':   10640 obs. of  13 variables:
   ..$ logprice      : num [1:10640] 12.3 12.1 13.1 14 12.5 ...
   ..$ bedrooms      : int [1:10640] 3 2 3 4 3 3 3 4 3 4 ...

I skipped the rest of 11 variables. My question is, how to call out the "logprice" in this data set, testdata[1]$logprice doesn't work

Kyle
  • 19
  • 1
  • 3

1 Answers1

0

In general, when working with lists [[]] returns a single element, whereas [] returns a list of elements. So when you try testdata[1] you're actually still returning a list (of one element) so you can't access what you want using $.

Mike H provided this solution as a comment, and Calum You was right in linking to this explanation if you want to understand the nuances a bit more.

Between all that hopefully the mistake isn't just obvious, but the explanation for it is too!

testdata[[1]]$logprice

LachlanO
  • 1,152
  • 8
  • 14