Plot matrix rows with distinct colors [closed] - r

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a matrix
B = matrix(c(1,2,4,1,4,2,1,3.5,4.2,2,2.2,6.5,3,1.2,7.7,1,2.1,1.6,3,5.2,8.2),
nrow = 7)
with 3 columns: the color column (colors from 1-5, representing blue,red,green,yellow,black), the x column and the y column.
I want to plot every points (x,y) with the color from the color column.
First question: what software is best to do so?
Second question: how can I do it with R?

Simple question finds simple answer:
plot(B[,2], B[,3], col=c("blue","red","green","yellow","black")[B[,1]])

Related

Find maximum of two variables in R [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this R code, and i want to assign to the Max Variable the maximum value of A and B
, would be something like :
Max<-(A,B)
How can i do it in R?
I searched but i couldn't find a max function.
Thanks
The function is literally max:
Max <- max(A, B)

How to Calculate Circumference of Pipe with Specified Pitch [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to Calculate Circumference [Perimeter] of a Pipe [Cylinder shape] with Specified Pitch?
Actually I want to find the length of thread to wind a pipe.
Is there any formula or formula name I can refer?
What you are looking for is the perimeter of an ellipse which is rather an ugly thing (see: http://www.mathsisfun.com/geometry/ellipse-perimeter.html). Your minor axis is the diameter of the pipe. The major axis is the hypotenuse of the right triangle formed from 1/2 of your pitch.

R - count number of list components [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I know that in R, you can index through a list with double brackets, i.e. mylist[[1]]. How do you count the number of elements in that list (not the number of elements in each list item, but the maximum n in mylist[[n]])? I tried NROW, NCOL, dim, among others.
Some example code for the desired behavior of some function num.items(list):
require(testthat)
mylist <- list(array(rnorm(4),dim=c(2,2)),array(rnorm(4),dim=c(2,2)))
expect_that( num.items(mylist), equals(2) )
length?
> length(mylist)
[1] 2

How to replace vector occurring numbers? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Let's say I have a vector of 10 elements called numbers in R
numbers <- c(0,1,1,1,0,0,1,0,1,0)
and I want to replace each occurrence of 1 to 5?
this should work
v[v==1]<-5

Finding i values where Y = a number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm a student just learning how to use R and thus far I've made a bit of progress. I'm snagging at a question which asks: For what values of i does Y equal 3?
the data set: c(3,5,2,3,5,4,4,2,3,5)
If I understand your question correctly, you want the index, i inside the data set (in this case, a vector) Y such that Y[i]=3?
Then you just need to use the which function. For more information, make sure you try reading the help files, which you can invoke using the command ?which or help(which)
Now, some code:
# Your data
Y <- c(3,5,2,3,5,4,4,2,3,5)
# Find the index where Y is equal to 3
which(Y==3, arr.ind=TRUE)
And welcome to SO. This is a pretty common question for beginners, so next time, make sure you Google or search around for a solution to elementary problems such as these. Have a good day.

Resources