Data:Vector sottoinsiemi vs. Lista sottoinsiemi
actors_vector <- c("Jack Nicholson", "Shelley Duvall", "Danny Lloyd",
"Scatman Crothers", "Barry Nelson")
reviews_factor <- factor(c("Good", "OK", "Good", "Perfect",
"Bad", "Perfect", "Good"),
levels = c("Bad", "OK", "Good", "Perfect"),
ordered = TRUE)
shining_list <- list(title = "The Shining",
actors = actors_vector,
reviews = reviews_factor)
shining_list
$title
[1] "The Shining"
$actors
[1] "Jack Nicholson" "Shelley Duvall" "Danny Lloyd" "Scatman Crothers"
[5] "Barry Nelson"
$reviews
[1] Good OK Good Perfect Bad Perfect Good
Levels: Bad < OK < Good < Perfect
$boxoffice
US Non-US
First release 39 47
Director's cut 18 14
Perché shining_list[[3]][3]
e shining_list$reviews[3]
ritorno:
[1] Good
Levels: Bad < OK < Good < Perfect
Mentre shining_list[[c(3,3)]]
ritorno:
[1] 3
Questa è una sezione sulla Vettore Subsetting vs. List Subsetting a DataCamp.
Hai un fattore nelle recensioni. Quando esegui l'estrazione con 'c (3,3)', viene convertito in un numero intero. –
L'OP sta chiedendo _why_, però. È in conflitto con _ "' [['può essere applicato ricorsivamente alle liste, in modo che se l'indice singolo' i' è un vettore di lunghezza 'p',' alist [[i]] 'è equivalente a' alist [[i1 ]] '...' [[ip]] 'fornisce tutti i risultati dell'indicizzazione finale in una lista.", ma 'shining_list [[3]] [[3]]' restituisce '[1] Buono' /' evels : Bad
hrbrmstr