How to extract one line from tbl_df as a vector? A simple subset with brackets [] gives 1 line tbl_df :
tbl_df
[]
library(dplyr) dat <- as_data_frame(mtcars) dat[2, ] Source: local data frame [1 x 11] mpg cyl disp hp drat wt qsec vs am gear carb (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) 1 21 6 160 110 3.9 2.875 17.02 0 1 4 4
A similar problem for Extract the dplyr tbl column as a vector , but with (I think) several different solutions.
Using the dplyr %>% operator
dplyr
%>%
library(dplyr) tbl_df(mtcars) %>% slice(2) %>% unlist(., use.names=FALSE)
Or we can use c with recursive=TRUE
c
recursive=TRUE
tbl_df(mtcars) %>% slice(2) %>% c(., recursive=TRUE) %>% unname
Source: https://habr.com/ru/post/1243808/More articles:use lodash to find a substring from an array of strings - javascriptWhy is SignalProducer not returning a signal? - iosNearest pair of glasses in 3+ dimensions (split and subdue) - algorithmWhat is the type ? - .net-assemblyUpload a GitHub account to R - rCalling const property inside a class in Laravel using a dynamic string - phpThink: How do I use the remember_me cookie after a user logs out? - ruby | fooobar.comconcatenating strings with mysql - phpHow can I get MatLab to search for a Visual C ++ compiler? - c ++Respond to my own project showing an error when I run it with "run-ios run-ios"? - javascriptAll Articles