0
a<- data.frame(x=runif(10), y = runif(10), Acc = 1)
b<- data.frame(x=runif(10), y = runif(10), Acc = 0)
ls<- list(a,b)

When I type ls[[1]] and ls[[2]], it prints the respective data frames. class(ls[1]) and class(ls[2]) shows me they are list. class(ls[[1]]) and class(ls[[2]]) shows me they are data frames. However when I type rm(ls[1]) or rm(ls[[1]]), I get the following error :

Error in rm(ls[1]) : ... must contain names or character strings.

I never see these kind of data frames which I create by a list in the environment window of R Studio. If I use rm(list=ls()), I can remove everything without retaining what I want. How shall remove ls[[1]] and ls[[2]]?

989
  • 12,579
  • 5
  • 31
  • 53
ARIMITRA MAITI
  • 303
  • 3
  • 4
  • 14
  • `ls[[1]]<-NULL` or `ls[[2]]<-NULL` – 989 Sep 13 '16 at 09:01
  • you are trying to remove a list object here so you can try `ls[-1]` or `ls[-2]` – Veerendra Gadekar Sep 13 '16 at 09:01
  • 1
    http://stackoverflow.com/questions/652136/how-can-i-remove-an-element-from-a-list – jogo Sep 13 '16 at 09:08
  • Thanks @moh3n ls[[1]]=NULL works, but if I type both 1 ls[[1]] followed by ls[[2]] it first deletes the second one Error in ls[[2]] : subscript out of bounds and then typing ls[1] deletes the first one. May be it is a matter of time or I am making a mistake – ARIMITRA MAITI Sep 13 '16 at 09:11
  • @ARIMITRAMAITI You have a list with two elements. If you delete one of the elements, how many elements are in the result? Indexing in R allways begins with index 1. – jogo Sep 13 '16 at 09:17

0 Answers0