0

Newbie question: Suppose that in R I have a list with 10'000 entries (numbers).

myList <- read.table ("my10000Vaulues")

Now I would like to remove all entries that are above some value (say 523.689). The resulting list should not have any white space in it.

Thanks for all hints

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
user974334
  • 49
  • 1
  • 2
  • First `myList` is not a list, it's a dataframe (possibly with one column). Second, it won't be read as numbers, it'll be factors or strings, due to the default `read.table(..., stringsAsFactors)` and unless you explicitly passed `colClasses`. Last, when you say "remove all white space", did you mean "empty rows", or "strings which contain whitespace", or both? Anyway, all of these are duplicates of many existing questions, so this question should probably be closed. – smci Aug 23 '18 at 00:32

2 Answers2

7

I'm guessing that your problem is that 'myList' really is a list -- a special type of list called a data frame -- and you want a numeric vector to work with.

One approach might be something like:

myNums <- myList[,1]
mySmallNUms <- myNums[myNums <= 523.689]
Patrick Burns
  • 887
  • 4
  • 7
2

You can do the following:

myListFiltered <- myList[myList <= 523.689]

Also have a look at: How can I remove an element from a list?

Community
  • 1
  • 1
Anatoliy
  • 1,350
  • 9
  • 9