Solved

R program matrix

Posted on 2015-01-11
2
236 Views
Last Modified: 2015-01-13
Hi,

I am trying to create a table that looks as follows:

    portfolio            return            risk
    SP                        6                    20
    NASDAQ            10                  25
The numbers are stored in variables and I am not hardcoding them and rest are headings.
How do I code for this.

Thanks
0
Comment
Question by:camper12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 40545273
> t <- matrix(c(60,20,10,25),ncol=2,byrow=TRUE)
> rownames(t) <- c("SP","NASDAQ")
> colnames(t) <- c("return","risk")
> t <- as.table(t)
> t

substitute your variables for the corresponding values in the collection
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 40545287
another version, same idea, using a matrix, but different syntax

> vals <- c(6,20,10,25)
> rows <- c("SP","NASDAQ")
> cols <- c("return","risk")
> tab <- matrix(vals,ncol=2,byrow=TRUE,dimnames=list(rows,cols))
> tab

I don't know of a way to put a label above the row names, that is, your "portfolio" label.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question