# StackOverflow - Solved

looking for some solutions? You are welcome.

## SOLVED: From python to R: Nested lists

Anisha Khosla:

I have spatial coordinate data from python which looks something like this:

[[179.0, -79.0], [127.0, 301.0], [-92.0, 310.0]]

I am analyzing this data in R, but I don't know how to grab individual coordinates i.e. how to get to [179.0, -79.0]. I have tried different indexing options but had no luck. Just for context, my dataframe has a column with python list of lists.

Any help would be much appreciated. Thanks!

R data when I do dfgood['click_pos'][[1]]:

[1] [[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]]

[2] [[-12.0, 78.0], [4.0, -186.0], [170.0, -138.0], [45.0, 254.0], [-153.0, 232.0], [-140.0, -37.0], [-227.0, -28.0], [-62.0, -12.0]]
.
.
.
[24] [[-14.0, 270.0], [-28.0, -164.0], [-302.0, -119.0], [-324.0, -278.0], [22.0, -259.0], [-316.0, -106.0]]
25 Levels: [[-102.0, 348.0], [-104.0, -37.0], [258.0, 87.0], [234.0, 418.0], [-93.0, 312.0], [118.0, -41.0]] ...

structure(list(X = 0:5, subjID = c(2, 2, 2, 2, 2, 2), block = c(2,
2, 2, 2, 2, 2), order_ntrials = c(1, 2, 3, 4, 5, 6), ntrials = c(13,
4, 8, 16, 1, 21), routelen = c(5, 7, 4, 7, 6, 7), ideal_x = c(-183,
4, -92, 19, -193, -133), ideal_y = c(-30, -186, 310, -26, 361,
138), subj_x = c(-115, -62, -114, -107, -418, -199), subj_y = c(-8,
-12, 323, 273, 305, 152), trial_rt = c(31.430577373947, 40.6340158929816,
26.0440646470524, 50.8890219930327, 34.8192964689806, 37.9083978550043
), home_rt = c(5.36384105798788, 3.99772735999431, 3.22768635000102,
5.48362414108124, 5.97196817304939, 5.93354129395448), all_pos = structure(c(8L,
3L, 19L, 15L, 16L, 5L), .Label = c("[[-102.0, 348.0], [-101.0, 352.0], [-101.0, 352.0], [-101.0, 352.0], [-102.0, 352.0],...,[118.0, -41.0]]",
"[[-11.0, 11.0], [-12.0, 14.0], [-12.0, 14.0],..., [6.0, 394.0]]",
"[[-12.0, 78.0], [-12.0, 78.0], [-12.0, 78.0],..., [6.0, 394.0]]",
), class = "factor"), all_pos_times = structure(c(19L, 10L, 17L,
6L, 12L, 9L), .Label = c("[15.970820963033475, 19.385453240014613, 19.89702452905476], ... "[2.4681653099833056, 5.662667237920687, 6.189063199912198]"
), class = "factor"), test_pos_idx = c(2, 2, 3, 5, 4, 6), mid_locs = structure(c(6L,
24L, 15L, 3L, 18L, 4L), .Label = c("[[-100.0, 163.0], [54.0, 149.0], [7.0, -355.0], [-244.0, -363.0]]",
"[[-104.0, -37.0], [258.0, 87.0], [234.0, 418.0]]", ...,"[[-122.0, 372.0], [-294.0, 372.0], [-235.0, -88.0], [19.0, -26.0], [-26.0, 277.0]]"), class = "factor"), test_pos = structure(c(4L,
23L, 14L, 17L, 5L, 2L), .Label = c("[-100.0, 163.0]", "[-133.0, 138.0]",
"[-150.0, -98.0]", "[-183.0, -30.0]", "[-193.0, 361.0]", "[-194.0, 213.0]",
"[-302.0, -119.0]", "[-308.0, -254.0]", ... , "[80.0, -210.0]"), class = "factor"),
exclude = c(0, 0, 0, 0, 0, 0)), .Names = c("X", "subjID",
"block", "order_ntrials", "ntrials", "routelen", "ideal_x", "ideal_y",
"subj_x", "subj_y", "trial_rt", "home_rt", "all_pos", "all_pos_times",
"click_pos", "click_pos_times", "test_pos_idx", "mid_locs", "test_pos",
"exclude"), row.names = c(NA, 6L), class = "data.frame")

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots