From python to R: Nested listsHow do I check if a list is empty?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to make a flat list out of list of lists?How do I list all files of a directory?Does Python have a string 'contains' substring method?

I'm flying to France today and my passport expires in less than 2 months

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

How do conventional missiles fly?

In Romance of the Three Kingdoms why do people still use bamboo sticks when paper had already been invented?

1960's book about a plague that kills all white people

How to prevent "they're falling in love" trope

Emailing HOD to enhance faculty application

What to put in ESTA if staying in US for a few days before going on to Canada

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Alternative to sending password over mail?

In a spin, are both wings stalled?

Can a rocket refuel on Mars from water?

How can I make my BBEG immortal short of making them a Lich or Vampire?

Combinations of multiple lists

What is the most common color to indicate the input-field is disabled?

Does a druid starting with a bow start with no arrows?

How can I fix/modify my tub/shower combo so the water comes out of the showerhead?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

Today is the Center

Were any external disk drives stacked vertically?

Anagram holiday

I Accidentally Deleted a Stock Terminal Theme

How can I tell someone that I want to be his or her friend?

What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?



From python to R: Nested lists


How do I check if a list is empty?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to make a flat list out of list of lists?How do I list all files of a directory?Does Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















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!



Clarification:



I was wondering if I can extract individual coordinates from
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]] ' in R.



This is what the data looks like in R. I loaded a csv file into a dataframe and each observation in df$click_pos has a value like
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]]'



So can I extract [-183.0, -30.0] from the above ?



dfgood['click_pos'][[1]][1] gives



[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]]
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]] ...


Note that typeof( dfgood['click_pos'][[1]][1]) gives type int



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]] ...


dput(head(df))--trimmed



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")









share|improve this question
























  • Welcome to stackoverflow! Please remember to always indent your code. You can do this by highlighting the code, then pressing CTRL+K or CMD+K, or by using 4 spaces. Alternatively you can wrap your code using ` ` ` , which will cause the code to appear like this.

    – Jane
    Mar 8 at 23:59







  • 1





    Ah, thank you! @Jane

    – Anisha Khosla
    Mar 9 at 0:06






  • 1





    You have shown us what your data looks like in python, but to help you, we need what you have in R. Please use dput to create a text version of your R data and paste it into your question. If your data is too long, you could use something like dput(head(MyData)) to show us a small sample in the format that you have.

    – G5W
    Mar 9 at 0:33











  • Sorry about that. The data set is quite big (or poorly managed). I tried to trim it down so it fits here. Seems quite messy to me. Let me know if there is another way I can give more information about what the R data looks like. This is from a csv file (python output). Thanks!

    – Anisha Khosla
    Mar 9 at 1:17

















1















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!



Clarification:



I was wondering if I can extract individual coordinates from
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]] ' in R.



This is what the data looks like in R. I loaded a csv file into a dataframe and each observation in df$click_pos has a value like
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]]'



So can I extract [-183.0, -30.0] from the above ?



dfgood['click_pos'][[1]][1] gives



[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]]
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]] ...


Note that typeof( dfgood['click_pos'][[1]][1]) gives type int



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]] ...


dput(head(df))--trimmed



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")









share|improve this question
























  • Welcome to stackoverflow! Please remember to always indent your code. You can do this by highlighting the code, then pressing CTRL+K or CMD+K, or by using 4 spaces. Alternatively you can wrap your code using ` ` ` , which will cause the code to appear like this.

    – Jane
    Mar 8 at 23:59







  • 1





    Ah, thank you! @Jane

    – Anisha Khosla
    Mar 9 at 0:06






  • 1





    You have shown us what your data looks like in python, but to help you, we need what you have in R. Please use dput to create a text version of your R data and paste it into your question. If your data is too long, you could use something like dput(head(MyData)) to show us a small sample in the format that you have.

    – G5W
    Mar 9 at 0:33











  • Sorry about that. The data set is quite big (or poorly managed). I tried to trim it down so it fits here. Seems quite messy to me. Let me know if there is another way I can give more information about what the R data looks like. This is from a csv file (python output). Thanks!

    – Anisha Khosla
    Mar 9 at 1:17













1












1








1








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!



Clarification:



I was wondering if I can extract individual coordinates from
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]] ' in R.



This is what the data looks like in R. I loaded a csv file into a dataframe and each observation in df$click_pos has a value like
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]]'



So can I extract [-183.0, -30.0] from the above ?



dfgood['click_pos'][[1]][1] gives



[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]]
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]] ...


Note that typeof( dfgood['click_pos'][[1]][1]) gives type int



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]] ...


dput(head(df))--trimmed



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")









share|improve this question
















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!



Clarification:



I was wondering if I can extract individual coordinates from
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]] ' in R.



This is what the data looks like in R. I loaded a csv file into a dataframe and each observation in df$click_pos has a value like
'[[-188.0, -261.0], [-183.0, -30.0], [88.0, -26.0], [11.0, 339.0], [-198.0, 323.0], [-115.0, -8.0]]'



So can I extract [-183.0, -30.0] from the above ?



dfgood['click_pos'][[1]][1] gives



[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]]
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]] ...


Note that typeof( dfgood['click_pos'][[1]][1]) gives type int



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]] ...


dput(head(df))--trimmed



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")






python r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 17:29







Anisha Khosla

















asked Mar 8 at 23:55









Anisha KhoslaAnisha Khosla

63




63












  • Welcome to stackoverflow! Please remember to always indent your code. You can do this by highlighting the code, then pressing CTRL+K or CMD+K, or by using 4 spaces. Alternatively you can wrap your code using ` ` ` , which will cause the code to appear like this.

    – Jane
    Mar 8 at 23:59







  • 1





    Ah, thank you! @Jane

    – Anisha Khosla
    Mar 9 at 0:06






  • 1





    You have shown us what your data looks like in python, but to help you, we need what you have in R. Please use dput to create a text version of your R data and paste it into your question. If your data is too long, you could use something like dput(head(MyData)) to show us a small sample in the format that you have.

    – G5W
    Mar 9 at 0:33











  • Sorry about that. The data set is quite big (or poorly managed). I tried to trim it down so it fits here. Seems quite messy to me. Let me know if there is another way I can give more information about what the R data looks like. This is from a csv file (python output). Thanks!

    – Anisha Khosla
    Mar 9 at 1:17

















  • Welcome to stackoverflow! Please remember to always indent your code. You can do this by highlighting the code, then pressing CTRL+K or CMD+K, or by using 4 spaces. Alternatively you can wrap your code using ` ` ` , which will cause the code to appear like this.

    – Jane
    Mar 8 at 23:59







  • 1





    Ah, thank you! @Jane

    – Anisha Khosla
    Mar 9 at 0:06






  • 1





    You have shown us what your data looks like in python, but to help you, we need what you have in R. Please use dput to create a text version of your R data and paste it into your question. If your data is too long, you could use something like dput(head(MyData)) to show us a small sample in the format that you have.

    – G5W
    Mar 9 at 0:33











  • Sorry about that. The data set is quite big (or poorly managed). I tried to trim it down so it fits here. Seems quite messy to me. Let me know if there is another way I can give more information about what the R data looks like. This is from a csv file (python output). Thanks!

    – Anisha Khosla
    Mar 9 at 1:17
















Welcome to stackoverflow! Please remember to always indent your code. You can do this by highlighting the code, then pressing CTRL+K or CMD+K, or by using 4 spaces. Alternatively you can wrap your code using ` ` ` , which will cause the code to appear like this.

– Jane
Mar 8 at 23:59






Welcome to stackoverflow! Please remember to always indent your code. You can do this by highlighting the code, then pressing CTRL+K or CMD+K, or by using 4 spaces. Alternatively you can wrap your code using ` ` ` , which will cause the code to appear like this.

– Jane
Mar 8 at 23:59





1




1





Ah, thank you! @Jane

– Anisha Khosla
Mar 9 at 0:06





Ah, thank you! @Jane

– Anisha Khosla
Mar 9 at 0:06




1




1





You have shown us what your data looks like in python, but to help you, we need what you have in R. Please use dput to create a text version of your R data and paste it into your question. If your data is too long, you could use something like dput(head(MyData)) to show us a small sample in the format that you have.

– G5W
Mar 9 at 0:33





You have shown us what your data looks like in python, but to help you, we need what you have in R. Please use dput to create a text version of your R data and paste it into your question. If your data is too long, you could use something like dput(head(MyData)) to show us a small sample in the format that you have.

– G5W
Mar 9 at 0:33













Sorry about that. The data set is quite big (or poorly managed). I tried to trim it down so it fits here. Seems quite messy to me. Let me know if there is another way I can give more information about what the R data looks like. This is from a csv file (python output). Thanks!

– Anisha Khosla
Mar 9 at 1:17





Sorry about that. The data set is quite big (or poorly managed). I tried to trim it down so it fits here. Seems quite messy to me. Let me know if there is another way I can give more information about what the R data looks like. This is from a csv file (python output). Thanks!

– Anisha Khosla
Mar 9 at 1:17












1 Answer
1






active

oldest

votes


















0














I had problems recreating your data, so I assumed you're coming from python and your data looked like this: [[179.0, -79.0], [127.0, 301.0], [-92.0, 310.0]] - python style.



Recreating it using R code:



df <- list(list(179.0, -79.0), 
list(127.0, 301.0),
list(-92.0, 310.0))


What you have here is a list of lists, and if you'd like to get an item using indexing you need to use [] .



First, in R it's always nice to use the str() function to understand your variable.



List of 3
$ :List of 2
..$ : num 179
..$ : num -79
$ :List of 2
..$ : num 127
..$ : num 301
$ :List of 2
..$ : num -92
..$ : num 310


We can see that we have a list with 3 list within it.
Next, we can start to get each list/item from the list using [] and indexing (don't forget that unlike python, R uses 1 indexing):



If will type df[1] will get to our first list:



[[1]]
[[1]][[1]]
[1] 179

[[1]][[2]]
[1] -79


But if will do df[[1]] will get the first items from our first list:



df[[1]]
[[1]]
[1] 179

[[2]]
[1] -79


If we'll use a second index like this df[[1]][1], we'll get our first item in our list:



[[1]]
[1] 179


I think that the picture from here and here is very useful:
enter image description here






share|improve this answer

























  • Thanks so much for the explanation! I think my problem is a little different though. I tried clarifying it more in my question. In short, typeof( dfgood['click_pos'][[1]][1]) gives type int

    – Anisha Khosla
    Mar 9 at 17:31











  • It looks like click_pos is a factor. So when you access an element, it gives you its value and not its label. Try to use varhandle::unfactor() or as.character(dfgood$click_pos) to unfactor/change the variable to a character vector.

    – DJV
    Mar 9 at 21:48











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072584%2ffrom-python-to-r-nested-lists%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I had problems recreating your data, so I assumed you're coming from python and your data looked like this: [[179.0, -79.0], [127.0, 301.0], [-92.0, 310.0]] - python style.



Recreating it using R code:



df <- list(list(179.0, -79.0), 
list(127.0, 301.0),
list(-92.0, 310.0))


What you have here is a list of lists, and if you'd like to get an item using indexing you need to use [] .



First, in R it's always nice to use the str() function to understand your variable.



List of 3
$ :List of 2
..$ : num 179
..$ : num -79
$ :List of 2
..$ : num 127
..$ : num 301
$ :List of 2
..$ : num -92
..$ : num 310


We can see that we have a list with 3 list within it.
Next, we can start to get each list/item from the list using [] and indexing (don't forget that unlike python, R uses 1 indexing):



If will type df[1] will get to our first list:



[[1]]
[[1]][[1]]
[1] 179

[[1]][[2]]
[1] -79


But if will do df[[1]] will get the first items from our first list:



df[[1]]
[[1]]
[1] 179

[[2]]
[1] -79


If we'll use a second index like this df[[1]][1], we'll get our first item in our list:



[[1]]
[1] 179


I think that the picture from here and here is very useful:
enter image description here






share|improve this answer

























  • Thanks so much for the explanation! I think my problem is a little different though. I tried clarifying it more in my question. In short, typeof( dfgood['click_pos'][[1]][1]) gives type int

    – Anisha Khosla
    Mar 9 at 17:31











  • It looks like click_pos is a factor. So when you access an element, it gives you its value and not its label. Try to use varhandle::unfactor() or as.character(dfgood$click_pos) to unfactor/change the variable to a character vector.

    – DJV
    Mar 9 at 21:48















0














I had problems recreating your data, so I assumed you're coming from python and your data looked like this: [[179.0, -79.0], [127.0, 301.0], [-92.0, 310.0]] - python style.



Recreating it using R code:



df <- list(list(179.0, -79.0), 
list(127.0, 301.0),
list(-92.0, 310.0))


What you have here is a list of lists, and if you'd like to get an item using indexing you need to use [] .



First, in R it's always nice to use the str() function to understand your variable.



List of 3
$ :List of 2
..$ : num 179
..$ : num -79
$ :List of 2
..$ : num 127
..$ : num 301
$ :List of 2
..$ : num -92
..$ : num 310


We can see that we have a list with 3 list within it.
Next, we can start to get each list/item from the list using [] and indexing (don't forget that unlike python, R uses 1 indexing):



If will type df[1] will get to our first list:



[[1]]
[[1]][[1]]
[1] 179

[[1]][[2]]
[1] -79


But if will do df[[1]] will get the first items from our first list:



df[[1]]
[[1]]
[1] 179

[[2]]
[1] -79


If we'll use a second index like this df[[1]][1], we'll get our first item in our list:



[[1]]
[1] 179


I think that the picture from here and here is very useful:
enter image description here






share|improve this answer

























  • Thanks so much for the explanation! I think my problem is a little different though. I tried clarifying it more in my question. In short, typeof( dfgood['click_pos'][[1]][1]) gives type int

    – Anisha Khosla
    Mar 9 at 17:31











  • It looks like click_pos is a factor. So when you access an element, it gives you its value and not its label. Try to use varhandle::unfactor() or as.character(dfgood$click_pos) to unfactor/change the variable to a character vector.

    – DJV
    Mar 9 at 21:48













0












0








0







I had problems recreating your data, so I assumed you're coming from python and your data looked like this: [[179.0, -79.0], [127.0, 301.0], [-92.0, 310.0]] - python style.



Recreating it using R code:



df <- list(list(179.0, -79.0), 
list(127.0, 301.0),
list(-92.0, 310.0))


What you have here is a list of lists, and if you'd like to get an item using indexing you need to use [] .



First, in R it's always nice to use the str() function to understand your variable.



List of 3
$ :List of 2
..$ : num 179
..$ : num -79
$ :List of 2
..$ : num 127
..$ : num 301
$ :List of 2
..$ : num -92
..$ : num 310


We can see that we have a list with 3 list within it.
Next, we can start to get each list/item from the list using [] and indexing (don't forget that unlike python, R uses 1 indexing):



If will type df[1] will get to our first list:



[[1]]
[[1]][[1]]
[1] 179

[[1]][[2]]
[1] -79


But if will do df[[1]] will get the first items from our first list:



df[[1]]
[[1]]
[1] 179

[[2]]
[1] -79


If we'll use a second index like this df[[1]][1], we'll get our first item in our list:



[[1]]
[1] 179


I think that the picture from here and here is very useful:
enter image description here






share|improve this answer















I had problems recreating your data, so I assumed you're coming from python and your data looked like this: [[179.0, -79.0], [127.0, 301.0], [-92.0, 310.0]] - python style.



Recreating it using R code:



df <- list(list(179.0, -79.0), 
list(127.0, 301.0),
list(-92.0, 310.0))


What you have here is a list of lists, and if you'd like to get an item using indexing you need to use [] .



First, in R it's always nice to use the str() function to understand your variable.



List of 3
$ :List of 2
..$ : num 179
..$ : num -79
$ :List of 2
..$ : num 127
..$ : num 301
$ :List of 2
..$ : num -92
..$ : num 310


We can see that we have a list with 3 list within it.
Next, we can start to get each list/item from the list using [] and indexing (don't forget that unlike python, R uses 1 indexing):



If will type df[1] will get to our first list:



[[1]]
[[1]][[1]]
[1] 179

[[1]][[2]]
[1] -79


But if will do df[[1]] will get the first items from our first list:



df[[1]]
[[1]]
[1] 179

[[2]]
[1] -79


If we'll use a second index like this df[[1]][1], we'll get our first item in our list:



[[1]]
[1] 179


I think that the picture from here and here is very useful:
enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 8:41

























answered Mar 9 at 8:17









DJVDJV

1,7391519




1,7391519












  • Thanks so much for the explanation! I think my problem is a little different though. I tried clarifying it more in my question. In short, typeof( dfgood['click_pos'][[1]][1]) gives type int

    – Anisha Khosla
    Mar 9 at 17:31











  • It looks like click_pos is a factor. So when you access an element, it gives you its value and not its label. Try to use varhandle::unfactor() or as.character(dfgood$click_pos) to unfactor/change the variable to a character vector.

    – DJV
    Mar 9 at 21:48

















  • Thanks so much for the explanation! I think my problem is a little different though. I tried clarifying it more in my question. In short, typeof( dfgood['click_pos'][[1]][1]) gives type int

    – Anisha Khosla
    Mar 9 at 17:31











  • It looks like click_pos is a factor. So when you access an element, it gives you its value and not its label. Try to use varhandle::unfactor() or as.character(dfgood$click_pos) to unfactor/change the variable to a character vector.

    – DJV
    Mar 9 at 21:48
















Thanks so much for the explanation! I think my problem is a little different though. I tried clarifying it more in my question. In short, typeof( dfgood['click_pos'][[1]][1]) gives type int

– Anisha Khosla
Mar 9 at 17:31





Thanks so much for the explanation! I think my problem is a little different though. I tried clarifying it more in my question. In short, typeof( dfgood['click_pos'][[1]][1]) gives type int

– Anisha Khosla
Mar 9 at 17:31













It looks like click_pos is a factor. So when you access an element, it gives you its value and not its label. Try to use varhandle::unfactor() or as.character(dfgood$click_pos) to unfactor/change the variable to a character vector.

– DJV
Mar 9 at 21:48





It looks like click_pos is a factor. So when you access an element, it gives you its value and not its label. Try to use varhandle::unfactor() or as.character(dfgood$click_pos) to unfactor/change the variable to a character vector.

– DJV
Mar 9 at 21:48



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072584%2ffrom-python-to-r-nested-lists%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme