1

I am running a simulation model that creates a large data frame as its output, with each column corresponding to the time-series of a particular variable:

data5<-as.data.frame(simulation3$baseline)

Occasionally I want to look at subsets, especially particular columns, of this data frame in order to get an idea of the output. For this I am using the View-function like so

View(data5[1:100,1])

for instance, if I wish to see the first 100 rows of column 1. Alternatively, I also sometimes do something like this, using the names of the time series:

timeframe=1:100
toAnalyse=c("u","u_n","u_e","u_nw")
View(data5[timeframe,toAnalyse])

In either case, there is an annoying display problem when I am trying to view a single column on its own (as for instance with View(data5[1:100,1])), whereby what I get looks like this:

Example 1

As you can see, the top of the table which would usually contain the name of the variable in the dataset instead contains a string of all values that the variable takes. This problem does not appear if I select 2 or more columns:

Example 2

Does anyone know how to get rid of this issue? Is there some argument that I can feed to View to make sure that it behaves nicely when I ask it to just show a single column?

SDR91
  • 23
  • 1
  • 1
  • 4

1 Answers1

5

View(data5[1:100,1, drop=FALSE])

When you access a single column of a data frame it is converted to a vector, drop=FALSE prevents that and retains the column name.

For instance:

> df
  n  s    b
1 2 aa TRUE
2 3 bb TRUE
3 5 cc TRUE
> df[, 1]
[1] 2 3 5
> df[, 1, drop=FALSE]
  n
1 2
2 3
3 5
Zach Kramer
  • 183
  • 1
  • 1
  • 7