Judy
Judy

Reputation: 53

R: sapply printing results

I have code that is doing this:

sapply(unique(groups.50),function(g)data$SEQUENCE_ID[groups.50 == g])

But in the RGui window, I can only scroll up to see some of the results. The first 10 or so doesn't show in the window (probably because my data is so large). How do I get it to show all of it, or alternatively, how do I print the first 10 results?

Thanks.

Upvotes: 0

Views: 1333

Answers (3)

Matthew Plourde
Matthew Plourde

Reputation: 44614

For scrolling through large datasets, the page function with method='print' is also pretty handy. It has the added benefit of not cluttering your command history with output.

Upvotes: 1

AndrewMacDonald
AndrewMacDonald

Reputation: 2950

You might try

x<-sapply(unique(groups.50),function(g)data$SEQUENCE_ID[groups.50 == g])
head(x)

But you should probably be using tapply instead?

Upvotes: 0

Blue Magister
Blue Magister

Reputation: 13363

Assuming your output of your function is a vector, save it to an object and then subset:

a <- sapply(unique(groups.50),function(g)data$SEQUENCE_ID[groups.50 == g])
a[1:10]

Or use head:

head(sapply(unique(groups.50),function(g)data$SEQUENCE_ID[groups.50 == g]),n=10)

Upvotes: 0

Related Questions