Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a table in a stack overflow (SO) question to use as a dataframe for an answer [duplicate]

Tags:

dataframe

r

Often a SO question includes a table like so:

"v1"    "v2"    "v3"
"A"     "a"      1
"B"     "b"      2
"C"     "c"      3

# or like so

 v1 v2 v3
 A  a  1
 B  b  2
 C  c  3

Rather than a dataframe like so:

df <-  data.frame(v1 = c("A", "B", "C"),
                  v2 = c("a", "b", "c"),
                  v3 = 1:3)

Is there a way to copy and paste the table version of the data from the question and use to work on in one's own console without manually converting the table into a dataframe?

like image 337
Peter Avatar asked Apr 20 '20 23:04

Peter


1 Answers

We can use soread from overflow after copying the lines

library(overflow)
soread()
#data.frame “mydf” created in your workspace
#  v1 v2 v3
#1  A  a  1
#2  B  b  2
#3  C  c  3

str(mydf)
#'data.frame':  3 obs. of  3 variables:
# $ v1: chr  "A" "B" "C"
# $ v2: chr  "a" "b" "c"
# $ v3: int  1 2 3

The package can be installed from github

source("http://jtilly.io/install_github/install_github.R")
install_github("mrdwab/overflow-mrdwab")
like image 84
akrun Avatar answered Sep 16 '22 14:09

akrun