Dear group, I am nearly beside myself. After an entire night spent on a niggling little detail, I am no closer to to the truth. I loaded an Excel file in .csv form into R. It apparentely loads as a list, but not the kind of list you can use. Oh no, it converts into a list that cannot be converted into an integer, numeric, or vector, only a matrix, whihc is useless without integers. How can I get a list of the form [1] 1,2,3,4,5 into the form [1] 1 [2] 2 [3] 3 [4] 4 [5] 5? Depending on hwo you define a list, apparentely, it goes one way or the other. x <- list(1:5) means you have [1] 1,2,3,4,5 y <- list(1,2,3,4,5) means you have [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 Can anyone help?# I woudl greatly appreciate it. Sincerely, Norman Goodacre --------------------------------- [[alternative HTML version deleted]]
?unlist> y <- list(1,2,3,4,5) > y[[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 [[5]] [1] 5> unlist(y)[1] 1 2 3 4 5>On 1/18/06, Norman Goodacre <perfumedlizard@yahoo.co.uk> wrote:> > Dear group, > > I am nearly beside myself. After an entire night spent on a niggling > little detail, I am no closer to to the truth. I loaded an Excel file in > .csv form into R. It apparentely loads as a list, but not the kind of list > you can use. Oh no, it converts into a list that cannot be converted into > an integer, numeric, or vector, only a matrix, whihc is useless without > integers. > > How can I get a list of the form [1] 1,2,3,4,5 into the form [1] 1 [2] > 2 [3] 3 [4] 4 [5] 5? Depending on hwo you define a list, apparentely, it > goes one way or the other. > > x <- list(1:5) means you have [1] 1,2,3,4,5 > y <- list(1,2,3,4,5) means you have [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 > > Can anyone help?# > > I woudl greatly appreciate it. > > Sincerely, > Norman Goodacre > > > > --------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve? [[alternative HTML version deleted]]
i am not sure i clearly understood... do you want to coerce a vector into a list of its elements ?! like this: split(1:5,1:5) Norman Goodacre a ??crit :> Dear group, > > I am nearly beside myself. After an entire night spent on a niggling little detail, I am no closer to to the truth. I loaded an Excel file in .csv form into R. It apparentely loads as a list, but not the kind of list you can use. Oh no, it converts into a list that cannot be converted into an integer, numeric, or vector, only a matrix, whihc is useless without integers. > > How can I get a list of the form [1] 1,2,3,4,5 into the form [1] 1 [2] 2 [3] 3 [4] 4 [5] 5? Depending on hwo you define a list, apparentely, it goes one way or the other. > > x <- list(1:5) means you have [1] 1,2,3,4,5 > y <- list(1,2,3,4,5) means you have [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 > > Can anyone help?# > > I woudl greatly appreciate it. > > Sincerely, > Norman Goodacre > > > >--------------------------------- > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > >
On Wed, 2006-01-18 at 12:27 +0000, Norman Goodacre wrote:> Dear group, > > I am nearly beside myself. After an entire night spent on a > niggling little detail, I am no closer to to the truth. I loaded an > Excel file in .csv form into R. It apparentely loads as a list, but > not the kind of list you can use. Oh no, it converts into a list that > cannot be converted into an integer, numeric, or vector, only a > matrix, whihc is useless without integers. > > How can I get a list of the form [1] 1,2,3,4,5 into the form [1] > 1 [2] 2 [3] 3 [4] 4 [5] 5? Depending on hwo you define a list, > apparentely, it goes one way or the other. > > x <- list(1:5) means you have [1] 1,2,3,4,5 > y <- list(1,2,3,4,5) means you have [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 > > Can anyone help?# > > I woudl greatly appreciate it. > > Sincerely, > Norman Goodacre >Presuming that you used read.csv() or similar, the imported CSV object should be a simple data frame. It is not truly clear here what your problem is relative to how you want to use the imported data. The difference between:> list(1:5)[[1]] [1] 1 2 3 4 5 and> list(1,2,3,4,5)[[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 [[5]] [1] 5 is that in the first case, you have a list with one element, which is a vector containing 5 elements:> str(list(1:5))List of 1 $ : int [1:5] 1 2 3 4 5 whereas in the second case, you have a list with five elements, each of which is a vector with one element:> str(list(1,2,3,4,5))List of 5 $ : num 1 $ : num 2 $ : num 3 $ : num 4 $ : num 5 Note also the not so subtle difference where in the first case, the result of the sequence 1:5 yields integers and in the second case, the elements are doubles (numeric), which is the default data type in R. Please provide additional details on what it is you are trying to do here and we can attempt to offer more specific guidance. HTH, Marc Schwartz
of course unlist()/as.list() do that !!! (sorry, i am tired) Norman Goodacre a ??crit :> Dear group, > > I am nearly beside myself. After an entire night spent on a niggling little detail, I am no closer to to the truth. I loaded an Excel file in .csv form into R. It apparentely loads as a list, but not the kind of list you can use. Oh no, it converts into a list that cannot be converted into an integer, numeric, or vector, only a matrix, whihc is useless without integers. > > How can I get a list of the form [1] 1,2,3,4,5 into the form [1] 1 [2] 2 [3] 3 [4] 4 [5] 5? Depending on hwo you define a list, apparentely, it goes one way or the other. > > x <- list(1:5) means you have [1] 1,2,3,4,5 > y <- list(1,2,3,4,5) means you have [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 > > Can anyone help?# > > I woudl greatly appreciate it. > > Sincerely, > Norman Goodacre > > > >--------------------------------- > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > >