Access the column using column header from variable [closed]











up vote
0
down vote

favorite












dist <- array(5, dim = c(61,61), dimnames = list(c(1:61),c(1:61)))

dist <- dist[-23,-29]

y <- 61


now I want to access the column with header = y, i.e. in this case dist$'61'
However, I want to do it in terms of y.



I have tried dist$y, dist$y and dist$'get("y")' but all of these returned NULL.



Can someone please help me with this syntax?










share|improve this question















closed as off-topic by Cath, Jaap, Sotos, phiver, wp78de Nov 19 at 18:09


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Cath, Jaap, Sotos, phiver, wp78de

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    $ is not suitable for arrays (it is quite surprising that it returns NULL and not an error). You can access the column "61" with dist[, as.character(y)] (or directly defining y as y <- "61").
    – Cath
    Nov 19 at 15:27








  • 2




    Or dist[,colnames(dist) %in% y]
    – Sotos
    Nov 19 at 15:30















up vote
0
down vote

favorite












dist <- array(5, dim = c(61,61), dimnames = list(c(1:61),c(1:61)))

dist <- dist[-23,-29]

y <- 61


now I want to access the column with header = y, i.e. in this case dist$'61'
However, I want to do it in terms of y.



I have tried dist$y, dist$y and dist$'get("y")' but all of these returned NULL.



Can someone please help me with this syntax?










share|improve this question















closed as off-topic by Cath, Jaap, Sotos, phiver, wp78de Nov 19 at 18:09


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Cath, Jaap, Sotos, phiver, wp78de

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    $ is not suitable for arrays (it is quite surprising that it returns NULL and not an error). You can access the column "61" with dist[, as.character(y)] (or directly defining y as y <- "61").
    – Cath
    Nov 19 at 15:27








  • 2




    Or dist[,colnames(dist) %in% y]
    – Sotos
    Nov 19 at 15:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











dist <- array(5, dim = c(61,61), dimnames = list(c(1:61),c(1:61)))

dist <- dist[-23,-29]

y <- 61


now I want to access the column with header = y, i.e. in this case dist$'61'
However, I want to do it in terms of y.



I have tried dist$y, dist$y and dist$'get("y")' but all of these returned NULL.



Can someone please help me with this syntax?










share|improve this question















dist <- array(5, dim = c(61,61), dimnames = list(c(1:61),c(1:61)))

dist <- dist[-23,-29]

y <- 61


now I want to access the column with header = y, i.e. in this case dist$'61'
However, I want to do it in terms of y.



I have tried dist$y, dist$y and dist$'get("y")' but all of these returned NULL.



Can someone please help me with this syntax?







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 15:22









Sotos

27k51540




27k51540










asked Nov 19 at 15:19









Saumya Pendyala

41




41




closed as off-topic by Cath, Jaap, Sotos, phiver, wp78de Nov 19 at 18:09


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Cath, Jaap, Sotos, phiver, wp78de

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Cath, Jaap, Sotos, phiver, wp78de Nov 19 at 18:09


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Cath, Jaap, Sotos, phiver, wp78de

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    $ is not suitable for arrays (it is quite surprising that it returns NULL and not an error). You can access the column "61" with dist[, as.character(y)] (or directly defining y as y <- "61").
    – Cath
    Nov 19 at 15:27








  • 2




    Or dist[,colnames(dist) %in% y]
    – Sotos
    Nov 19 at 15:30














  • 2




    $ is not suitable for arrays (it is quite surprising that it returns NULL and not an error). You can access the column "61" with dist[, as.character(y)] (or directly defining y as y <- "61").
    – Cath
    Nov 19 at 15:27








  • 2




    Or dist[,colnames(dist) %in% y]
    – Sotos
    Nov 19 at 15:30








2




2




$ is not suitable for arrays (it is quite surprising that it returns NULL and not an error). You can access the column "61" with dist[, as.character(y)] (or directly defining y as y <- "61").
– Cath
Nov 19 at 15:27






$ is not suitable for arrays (it is quite surprising that it returns NULL and not an error). You can access the column "61" with dist[, as.character(y)] (or directly defining y as y <- "61").
– Cath
Nov 19 at 15:27






2




2




Or dist[,colnames(dist) %in% y]
– Sotos
Nov 19 at 15:30




Or dist[,colnames(dist) %in% y]
– Sotos
Nov 19 at 15:30












2 Answers
2






active

oldest

votes

















up vote
0
down vote













By doing dist <- dist[-23,-29] you removed a line and a column, meaning that dist[, y] with y equal to 61 is now out of bounds. But you know that already.



Indeed what you need to do is to select the name 61, and therefore
dist[, as.character(y)] should give you what you want.






share|improve this answer




























    up vote
    0
    down vote













    dist$y expects y to be the actual name of the column.



    If y is a variable containing the name of the column, you want to use the following syntax:
    dist[, y]



    Make sure that y is a character!






    share|improve this answer



















    • 1




      Did you try that?
      – Sotos
      Nov 19 at 15:32










    • I have...but with wrong inputs. My bad!
      – 12b345b6b78
      Nov 19 at 15:38


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    By doing dist <- dist[-23,-29] you removed a line and a column, meaning that dist[, y] with y equal to 61 is now out of bounds. But you know that already.



    Indeed what you need to do is to select the name 61, and therefore
    dist[, as.character(y)] should give you what you want.






    share|improve this answer

























      up vote
      0
      down vote













      By doing dist <- dist[-23,-29] you removed a line and a column, meaning that dist[, y] with y equal to 61 is now out of bounds. But you know that already.



      Indeed what you need to do is to select the name 61, and therefore
      dist[, as.character(y)] should give you what you want.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        By doing dist <- dist[-23,-29] you removed a line and a column, meaning that dist[, y] with y equal to 61 is now out of bounds. But you know that already.



        Indeed what you need to do is to select the name 61, and therefore
        dist[, as.character(y)] should give you what you want.






        share|improve this answer












        By doing dist <- dist[-23,-29] you removed a line and a column, meaning that dist[, y] with y equal to 61 is now out of bounds. But you know that already.



        Indeed what you need to do is to select the name 61, and therefore
        dist[, as.character(y)] should give you what you want.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 15:26









        fzenoni

        1114




        1114
























            up vote
            0
            down vote













            dist$y expects y to be the actual name of the column.



            If y is a variable containing the name of the column, you want to use the following syntax:
            dist[, y]



            Make sure that y is a character!






            share|improve this answer



















            • 1




              Did you try that?
              – Sotos
              Nov 19 at 15:32










            • I have...but with wrong inputs. My bad!
              – 12b345b6b78
              Nov 19 at 15:38















            up vote
            0
            down vote













            dist$y expects y to be the actual name of the column.



            If y is a variable containing the name of the column, you want to use the following syntax:
            dist[, y]



            Make sure that y is a character!






            share|improve this answer



















            • 1




              Did you try that?
              – Sotos
              Nov 19 at 15:32










            • I have...but with wrong inputs. My bad!
              – 12b345b6b78
              Nov 19 at 15:38













            up vote
            0
            down vote










            up vote
            0
            down vote









            dist$y expects y to be the actual name of the column.



            If y is a variable containing the name of the column, you want to use the following syntax:
            dist[, y]



            Make sure that y is a character!






            share|improve this answer














            dist$y expects y to be the actual name of the column.



            If y is a variable containing the name of the column, you want to use the following syntax:
            dist[, y]



            Make sure that y is a character!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 19 at 18:24

























            answered Nov 19 at 15:22









            12b345b6b78

            685115




            685115








            • 1




              Did you try that?
              – Sotos
              Nov 19 at 15:32










            • I have...but with wrong inputs. My bad!
              – 12b345b6b78
              Nov 19 at 15:38














            • 1




              Did you try that?
              – Sotos
              Nov 19 at 15:32










            • I have...but with wrong inputs. My bad!
              – 12b345b6b78
              Nov 19 at 15:38








            1




            1




            Did you try that?
            – Sotos
            Nov 19 at 15:32




            Did you try that?
            – Sotos
            Nov 19 at 15:32












            I have...but with wrong inputs. My bad!
            – 12b345b6b78
            Nov 19 at 15:38




            I have...but with wrong inputs. My bad!
            – 12b345b6b78
            Nov 19 at 15:38



            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python