Solved

R program matrix

Posted on 2015-01-11
2
248 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Make the most of your online learning experience.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

695 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