Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the number of columns using R in Linux

Tags:

r

This may seem menial, but it affects my productivity. I am using R in terminal mode on Linux. Unlike the Windows IDE, Linux limits the number of columns to 80, thus making harder the inspection of data sets. Is there a way to set the max number of columns?

like image 751
gappy Avatar asked Jul 23 '09 15:07

gappy


People also ask

How do I count the number of columns in R?

The ncol() function in R programming That is, ncol() function returns the total number of columns present in the object.

How do I reduce the number of columns in R?

The most easiest way to drop columns is by using subset() function. In the code below, we are telling R to drop variables x and z. The '-' sign indicates dropping variables. Make sure the variable names would NOT be specified in quotes when using subset() function.

How do I add a variable to a Dataframe in R?

To add a new column to a dataframe in R you can use the $-operator. For example, to add the column “NewColumn”, you can do like this: dataf$NewColumn <- Values . Now, this will effectively add your new variable to your dataset.


2 Answers

Here is a function I have in my ~/.Rprofile file:

wideScreen <- function(howWide=Sys.getenv("COLUMNS")) {   options(width=as.integer(howWide)) } 

Calling the function without the howWide argument sets the column to be the width of your terminal. You can optionally pass in the argument to set the width to an arbitrary number of your choosing.

Almost like Josh's suggestion, but less magic :-)

like image 199
Steve Lianoglou Avatar answered Oct 20 '22 11:10

Steve Lianoglou


Set it with something like

options("width"=200) 

which is in fact what I have in ~/.Rprofile. See help(options) for details.

like image 31
Dirk Eddelbuettel Avatar answered Oct 20 '22 11:10

Dirk Eddelbuettel