[R] creating vectors from data-frames

2012-01-08 Thread Philip Robinson
I am having a problem with creating a vector from a rows or columns, I searched around and found as.vector(x), but it does not seem to do what it says it does I have included an example below, of doing what would seem to be the method required to create a vector, but instead it creates a

Re: [R] creating vectors from data-frames

2012-01-08 Thread David Winsemius
On Jan 8, 2012, at 3:12 PM, Philip Robinson wrote: I am having a problem with creating a vector from a rows or columns, I searched around and found as.vector(x), but it does not seem to do what it says it does I have included an example below, of doing what would seem to be the method

[R] creating vectors with three variables out of three datasets

2010-11-04 Thread DomDom
Hi there, i´ve got a problem with how to create a vector with three variables out of three seperate ascii files. These three ascii files contain pixel information of the same image but different bands and i need a matrix of vectors, with each vector containing the corresponding pixel values

Re: [R] creating vectors with three variables out of three datasets

2010-11-04 Thread Erik Iverson
DomDom wrote: Hi there, i´ve got a problem with how to create a vector with three variables out of three seperate ascii files. These three ascii files contain pixel information of the same image but different bands and i need a matrix of vectors, with each vector containing the

Re: [R] creating vectors with three variables out of three datasets

2010-11-04 Thread DomDom
okay sorry. i´ve got three ascii files with pixel values without any header information. so if the first line of the three ascii files are: ascii1: 11 12 13 ascii2: 14 15 16 ascii3: 17 18 19 i would like a new matrix with: 11,14,17;12,15,18;13,16,19; thx -- View this message in context:

Re: [R] creating vectors with three variables out of three datasets

2010-11-04 Thread jim holtman
Is this what you want: x V1 V2 V3 V4 1 ascii1: 11 12 13 2 ascii2: 14 15 16 3 ascii3: 17 18 19 z - as.matrix(x[,-1]) z V2 V3 V4 [1,] 11 12 13 [2,] 14 15 16 [3,] 17 18 19 as.vector(z) [1] 11 14 17 12 15 18 13 16 19 On Thu, Nov 4, 2010 at 6:05 PM, DomDom realown...@msn.com wrote:

Re: [R] Creating vectors

2010-08-12 Thread clips10
Thanks for the help, I tried to apply this to a vector with two columns, well I suppose it is not a vector but for instance like this: [,1] [,2] [1,]1 2 [2,]2 3 [3,]1 2 [4,]1 2 [5,]3 4 and return a vector : 1,2,1,1,3, so that it recognises

Re: [R] Creating vectors

2010-08-12 Thread TGS
I think I understand your question and the following would produce the result you've posted. (x - matrix(c(1, 2, 2, 3, 1, 2, 1, 2, 3, 4), nrow=5, byrow=TRUE)) On Aug 12, 2010, at 5:41 AM, clips10 wrote: Thanks for the help, I tried to apply this to a vector with two columns, well I suppose

Re: [R] Creating vectors

2010-08-12 Thread clips10
I think your code will work but only for the two columns I gave. I used those as an example but my actual data is 200 in length with two columns and I need code that will give a label to each unique pair but still have the original length for instance, one that will turn something such as

Re: [R] Creating vectors

2010-08-12 Thread JesperHybel
You can use following scriptI think #create a vector of random numbers on which to test script v-sample(1:3,size=90,replace=TRUE) #creates two matrixes out of vector v which can be assigned to M to test script M2-matrix(v,ncol=2) M3-matrix(v,ncol=3) M- #Assign you're matrix or a

Re: [R] Creating vectors

2010-08-11 Thread Wu Gong
Hi, Try ?unique please. x - c(2,2,9,4,6,2,4,4,6,8,6) # Original vector unique(x) #New vector only has unique elements sort(unique(x)) # Ordered Regards, Wu - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2321884.html Sent

[R] Creating vectors

2010-08-11 Thread clips10
I didn't really know what to post as the topic subject, but I have a vector, for instance (2,2,4,6,2,4,4,6,8,6) and I want to create another vector which is just numbers from 1 to 4 since there are only 4 unique numbers in my vector, so for instance 2 would be 1, 4 would be 2, 6 would be 3, and 8

Re: [R] Creating vectors

2010-08-11 Thread Ben Bolker
clips10 m.mcquillan at lancaster.ac.uk writes: I didn't really know what to post as the topic subject, but I have a vector, for instance (2,2,4,6,2,4,4,6,8,6) [... snip to make gmane happy ...], so my new vector would be (1,1,2,3,1,2,2,3,4,3). x - c(2,2,4,6,2,4,4,6,8,6) as.numeric(factor(x))

Re: [R] Creating vectors

2010-08-11 Thread Michael Bedward
Here's another way... x - c(2,2,4,6,2,4,4,6,8,6) match(x, unique(x)) Produces... [1] 1 1 2 3 1 2 2 3 4 3 On 12 August 2010 01:48, clips10 m.mcquil...@lancaster.ac.uk wrote: I didn't really know what to post as the topic subject, but I have a vector, for instance (2,2,4,6,2,4,4,6,8,6) and I

[R] creating vectors from a list

2009-09-28 Thread Christina Rodemeyer
Hi guys, I have a list of 250 numbers as a result of using the ?by function! List of 246  $ 0   : num [1:28] 22 11 31...  $ 1   : num [1:15] 12 14 9 ... .. .. ..  - attr(*, dim)= int 250  - attr(*, dimnames)=List of 1 The problem is that each list of 250 has different length! I would like to

Re: [R] creating vectors from a list

2009-09-28 Thread Gabor Grothendieck
Try this: L - list(`0` = 1:4, `1` = 2:3) sum(L$`0`) [1] 10 with(L, sum(`0`)) [1] 10 # not recommended tho' this is closest to what you asked for attach(L) sum(`0`) [1] 10 On Mon, Sep 28, 2009 at 10:57 AM, Christina Rodemeyer christinarodeme...@yahoo.de wrote: Hi guys, I have a list

Re: [R] creating vectors from a list

2009-09-28 Thread Henrique Dallazuanna
Try this: lapply(names(L), function(l)assign(sprintf('vector_%s', l), L[l], envir = globalenv())) ls() On Mon, Sep 28, 2009 at 11:57 AM, Christina Rodemeyer christinarodeme...@yahoo.de wrote: Hi guys, I have a list of 250 numbers as a result of using the ?by function! List of 246  $ 0   :