Solved

R program matrix

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
t-sql sp_addlinkedserver possible risks 3 94
Full Screen problem when auto scale IFRAME 2 103
Work with App store 7 68
Using Third Party DLL with Access VBA 14 41
This is an explanation of a simple data model to help parse a JSON feed
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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.

860 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