I want to split this df into bins based on the variable Quality. However, it is extremely right skewed 

```
     TSI2         YRI       Chromosome Quality
a1 0.03829518 0.050231431         22   0.860
a2 0.03110103 0.010192455         22   0.938
a3 0.03141379 0.060045625         22   0.848

```

This is a hist of Quality. 

[![enter image description here](https://i.stack.imgur.com/7yPPx.png)](https://i.stack.imgur.com/7yPPx.png) 

ll of the ways I have tried to bin the data so far have resulted in bins with very different numbers of samples in each.

```
totalResults$groups = cut(totalResults$Quality, 10)

```

Is there a way to force the bins to have even numbers of samples in each?

thanks
['https://Stackoverflow.com/questions/48646089', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5784757/']
Applying the `FileStream` approach - as already mentioned - use the `FileStream` [constructor](https://learn.microsoft.com/en-us/dotnet/api/system.io.filestream.-ctor?view=netframework-4.8#System_IO_FileStream__ctor_System_String_System_IO_FileMode_System_IO_FileAccess_System_IO_FileShare_System_Int32_) that accepts a `bufferSize` argument, which specifies the amount of bytes being read into memory.  

*(You can overrule the default value (`4096`) to fit your environment.)*

```
public FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize);

```

> 
> **bufferSize**:  
> 
>  A positive System.Int32 value greater than 0 indicating
>  the buffer size.  
> 
>  The default buffer size is 4096.
> 
> 
> 

```
public IActionResult GetFile()
{ 
    var filePath = @"c:\temp\file.mpg"; // Your path to the audio file.
    var bufferSize = 1024;
    var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize);            
    return File(fileStream, "audio/mpeg");
}

```

Note that there's no need to dispose the `fileStream`; the `File` method takes care of this.

---

To clarify:

When passing in a `FileStream`, its content is being read in chunks (matching the configured buffersize).  

Concrete, this means that its `Read` method (`int Read (byte[] array, int offset, int count)`) gets executed repeatedly untill all bytes have been read, ensuring that no more than the given number of bytes are stored in memory. 

So the scalability is within the less memory usage, as memory is a resource that can come under pressure if the size of the file is high, especially in combination with a high read frequency (of this or of other files)
which might cause out of memory problems.
*Posting as a community wiki, since it doesn't technically answer the question, but suggested code won't work as a comment.*

You can return a stream directly from `FileResult`, so there's no need to manually read from it. In fact, your code doesn't actually "stream", since you're basically reading the whole stream into memory, and then returning the `byte[]` at the end. Instead, just do:

```
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
    return File(fileStream, "audio/mpeg");
}

```

Or even simpler, just return the file path, and let `FileResult` handle it completely:

```
return File(System.IO.File.OpenRead(filePath), "audio/mpeg");

```