Hello !
I'm new to R, and would like to know if we can merge c(1,2) and c(3,4) into c( c(1,2),c(3,4) ) without concatenation. I don't want to obtain c(1,2,3,4).
Thanks a lot !
Lisa
Hello !
I'm new to R, and would like to know if we can merge c(1,2) and c(3,4) into c( c(1,2),c(3,4) ) without concatenation. I don't want to obtain c(1,2,3,4).
Thanks a lot !
Lisa
You can create a list:
list( c(1,2),c(3,4) )
Thanks a lot for your help martin.R !
Now, with a list : list( c(1,2), c(3,4), c(5,6), c(7,8) ), can I create a matrix 2*2 with each element of the matrix being one vector of my list ?
Lisa
can I create a matrix 2*2 with each element of the matrix being one vector of my list ?
no, because a matrix cant have a vector as an element, it has to be a single entry.
perhaps you can operate in a data.frame, especially tibbles, that can support list columns with complex elements.
I think it would be easier to guide you if you provided context. What are your starting ingredients, and what are your goals ?
I don't believe that's possible as a matrix.
A data.frame is a list of vectors though, so you could try using that.
EDIT: nirgrahamuk beat me to it.
Thank you both for trying to help me !
I want to create a trapping grid, with traps located this way :
A1 B1 C1 D1 E1 F1 G1 H1 I1 J1
A2 B2 ........
.
.
.
A10
As I will have to measure distances between the traps, I want my trap positions to look like a position vector : c("A1",1,1) for example, or c("B1",2,1) for example.
Then I wanted to have a 10*10 matrix with all elements being a position vector, but I guess I'll have to change for a data frame !
Not sure whether I understand your ultimate goal but it seems to me that you have "names" of traps (A1, B1 etc.) and their positions (x- and y-coordinate). You could simply store that in a data.frame, such as:
a <- data.frame(name = c("A1", "B1", "A2", "B2"), x = c(1, 1, 2, 2), y = c(1, 2, 1, 2))
And then compute the distances using the stats::dist()
function, e.g.
dist(a[, c(2,3)])
thank you for this answer jkurle !
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.