0

I created hashes with key, value pair. mydata is dataframe

myhash<-list(
slno= c('a','b','c'),
code= c('AKS','STU','RMS')
)

for (key in names(thisdict)){
  for (value in thisdict[key]){
    for (i in value){
      print(mydata$key)
      sum(mydata[mydata$key == value[i],'W'], na.rm=TRUE)

    }
  }
}

so while using mydata$key i'm not able to acccess as mydata$slno is there any solution for this.

D A
  • 11
  • 4
  • You have multiple errors in your R code. On line 3, you have an extra `,` which leaves an empty 3rd argument. On line 7, you need `myhash[[key]]`. Finally, on line 8, you need to more clearly define what you are trying to do, but you might want `mydata[,key]` or `mydata[,value]`. – Ian Campbell Apr 21 '21 at 04:34
  • See also: [Difference between operators for subsetting](https://stackoverflow.com/questions/45918827/difference-between-and-operators-for-subsetting) and [The difference between bracket and double bracket for accessing the elements of a list or dataframe](https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el) – Ian Campbell Apr 21 '21 at 04:36
  • @IanCampbell I have edited the code can you please take a look. so here key is also column in my dataset so ```mydata$key``` should be some thing like ```mydata$slno``` and it should sum all the matching with value – D A Apr 21 '21 at 04:56

0 Answers0