Reputation: 7051
My customer has a Python output in abc.txt such like:
[[1.1,2.2,3.3,
1.2,2.3,3.4]
[2.1,2.2,2.3,
3.1,3.2,3.4]]
My question is how to read it into R such like:
df <- data.frame(a=c(1.1,2.2,3.3,1.2,2.3,3.4),
b=c(2.1,2.2,2.3,3.1,3.2,3.4))
df
a b
1 1.1 2.1
2 2.2 2.2
3 3.3 2.3
4 1.2 3.1
5 2.3 3.2
6 3.4 3.4
Upvotes: 1
Views: 54
Reputation: 887571
An option is reticulate
library(reticulate)
source_python('abc.txt')
data.frame(setNames(v1, c('a', 'b')))
# a b
#1 1.1 2.1
#2 2.2 2.2
#3 3.3 2.3
#4 1.2 3.1
#5 2.3 3.2
#6 3.4 3.4
#abc.txt
v1 = [[1.1,2.2,3.3,
1.2,2.3,3.4],
[2.1,2.2,2.3,
3.1,3.2,3.4]]
Upvotes: 2