search for: unlist

Displaying 20 results from an estimated 2155 matches for "unlist".

2008 Nov 06
3
unlist & dataframes
Dear all, I would like to know whether it is possible to unlist elements and keep the original format of the data. To make it more clear, let me give an exemple: I have a list l of dataframes that I created with apply but which looks like this: x1=data.frame(Name=LETTERS[1:2],Age=1:2) x2=data.frame(Name=LETTERS[3:4],Age=3:4) l=list(x1,x2) l [[1]] Name Age 1...
2011 May 19
1
Feature request: extend functionality of 'unlist()' by args 'delim=c("/", "_", etc.)' and 'keep.special=TRUE/FALSE'
...;s exists a more formal channel (e.g. as for bug reports), I'd appreciate a pointer. I work a lot with named nested lists with arbitrary degrees of "nestedness". In order to retrieve the names and/or values of "bottom layer/bottom tier", I love the functionality of 'unlist()', or 'names(unlist(x))', respectively as it avoids traversing the nested lists via recursive loop constructs. I'm also aware that the general suggestion is probably to keep nestedness as low as possible when working with lists, but arbitrary deeply nested lists came in quite...
2008 Aug 20
0
unlist on nested lists of factors (PR#12572)
Here is a description and a proposed solution for a bug in unlist(). I've used version 2.7.2 RC (2008-08-18 r46382) to look at this, under linux. unlist(recursive=TRUE) incorrectly returns a factor with zero levels when passed either a nested list of factors, or a data frame containing only factor columns. You can't print() the result. x <- list(lis...
2007 May 13
2
relist, an inverse operator to unlist
Hi all, I wrote a function called relist, which is an inverse to the existing unlist function: http://www.econ.upenn.edu/~clausen/computing/relist.R Some functions need many parameters, which are most easily represented in complex structures. Unfortunately, many mathematical functions in R, including optim, nlm, and grad can only operate on functions whose domain is a ve...
2008 Oct 24
1
unlist change the ordered type
Hi the list, unlist respect the all the atomic type except orderd (it change of ordered into factor) : ### integer class(unlist(list(1:5,1:3))) #[1] "integer" ### numeric class(unlist(list(1.2,3.5))) #[1] "numeric" ### character class(unlist(list("e","e"))) #[1] "charac...
2007 Jan 17
2
problem with unlist POSIX date at midnight
Dear R-users, I use unlist of POSIX dates to extract the year, hour etc. With that I can search for files in my database which are in the form 'yyyymmddhh_synops.txt' However, I get stucked during midnight where unlist just gives NA's. The script is given below, the problem accurs at acc.period[16] (midnight)....
2010 Sep 26
4
Problem with unlist
Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.33333 So I would like to get for each element of the list the...
2011 May 26
2
What am I doing wrong with sapply ?
Statement 9 using sapply does not seem to give the correct answer (or at least to me). Yet I do what I think is the same thing with statement 11 and I get the answer I'm looking for. 9 : s <-sapply(unlist(v[c(1:length(v))]), max) 11: for(i in 1 :length(v)) v1[i] <- max(unlist(v[i])) Shouldn't I get the same answer ? library(XML) rm(list=ls()) url <- "http://webapp.montcopa.org/sherreal/salelist.asp?saledate=05/25/2011" tbl <-data.frame(readHTMLTable(url))[2:404, c(3,5,6,8,...
2016 Dec 02
3
unlist strips date class
Is this a bug? > unlist(list(as.Date("2015-01-01"))) [1] 16436 [[alternative HTML version deleted]]
2011 Feb 04
3
lapply, strsplit, and list elements
...t;349", "349"), c("340", "340", "367", "455", "D13"), c("600", "128", "128") ) I figured out that for a single element of x the following works unlist( lapply( strsplit( unlist( strsplit(x[1], "\\,") ), "/"), "[", 1) ) but due to "unlist" it doesn't provide the required result if extended to all elements of x unlist(lapply(strsplit( unlist( lapply(x, strsplit, "\\,")), "/"), "...
2013 Sep 27
2
Locating inefficient code
...d ports. That is all. Can this code improved ? data <- read.table("D:\\Log Analysis\\26-9-2013\\concurrentusage-node1",sep="",header=T,stringsAsFactors=FALSE, fill=TRUE) var <- c("Foreign.Address") data[,var] <- sapply(data[,var],function(x) ifelse(length(unlist(str_split(x,":")))==5,unlist(str_split(x,":"))[4],unlist(str_split(x,":"))[1])) var <- c("Local.Address") data[,var] <- sapply(data[,var],function(x) ifelse(length(unlist(str_split(x,":")))==5,paste(unlist(str_split(x,":"))[4],&quot...
2012 Jun 19
1
need help with unlist(), losing NULL values
Hi, I have a very rudimentary kind of question on using unlist(). I am parsing a bunch of JSON text using rjson package. Some data elements in a dictionary happen to be null which rjson parses correctly. > fromJSON(json_str='{"query":{"A":10, "B":null, "C":"hello"}, "query":{"A":...
2006 Oct 29
1
Help with unlist
Dear r-helpers, I have a list whose elements are > str(durCut[[1]]) Ord.factor w/ 5 levels "vLow"<"low"<"med"<..: 3 2 5 2 2 2 4 4 3 5 ... How do I unlist durCut into an ordered factor? > str(unlist(durCut)) int [1:3024] 3 2 5 2 2 2 4 4 3 5 ... _____________________________ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 Parcels: Room 102 Gilmer Hall...
2016 Dec 05
1
unlist strips date class
On 02 Dec 2016, at 23:13 , Herv? Pag?s <hpages at fredhutch.org> wrote: > More generally one might reasonably expect 'unlist(x)' to be equivalent > to 'do.call(c, x)' on a list 'x' where all the list elements are atomic > vectors: Well, both are generic, and e.g. there is no "Date" method for unlist(), but there is for c(). It is not clear that the two should be kept in lockstep and t...
2008 Aug 20
0
unlist on nested pairlists
unlist(recursive=FALSE) returns NULL elements when passed a nested pairlist containing non-NULL data: x <- pairlist(pairlist(1:2)) unlist(x, recursive=FALSE) ## [[1]] ## NULL version 2.7.2 RC (2008-08-18 r46382) under linux I'm unaware of any motivation for constructing the above data structure,...
2010 Jun 26
2
Recursive indexing failed at level 2
Dear fellow R users, I am replacing elements of a list like so: pulse_subset[[1:20]]=unlist(pulse[i])[1:20] where pulse is a list of lists, and pulse [i] has >20 values. This gives the error "Recursive Indexing failed at level 2". But, interestingly this instruction is part of a loop which has gone through about 200,000 iterations before giving this error. Actual code:...
2011 Aug 30
4
weird apply() behavior
Hi, I had a weird results from using apply(). Here is an simple example: > y<-data.frame(list(a=c(1,NA),b=c('2k','0'))) > y ??? a???? b 1? 1?? 2k 2 NA?? 0 > apply(y,1,function(x){x<-unlist(x); if (!is.na(x[2]) & x[2]=='2k' & !is.na(x[1]) & x[1]=='1') 1 else 0} ) This should print "1 0" as output, as demonstrated by: > apply(y[1,],1,function(x){x<-unlist(x); if (!is.na(x[2]) & x[2]=='2k' & !is.na(x[1]) & x[1]=='1...
2018 May 08
2
unlist errors on a nested list of empty lists
Reproducible example: x <- list(list(list(), list())) unlist(x) *> Error in as.character.factor(x) : malformed factor* What should happen: unlist(x) > NULL R.version platform x86_64-apple-darwin15.6.0 arch x86_64 os darwin15.6.0 system x86_64, darwin15.6.0 status major 3 minor 5.0 year...
2008 Jun 12
2
numbers as part of long character
Hi, I'm looking for some way to pick up the numbers which are contained and buried in a long character. For example, outtree.new="(((B:1204.25,E:1204.25):7581.11,F:8785.36):8353.85,C:17139.21);" num.char = unlist(strsplit(unlist(strsplit(unlist(strsplit(unlist(strsplit(unlist(strsplit(outtree.new,")",fixed=TRUE)),"(",fixed=TRUE)),":",fixed=TRUE)),",",fixed=TRUE)),";",fixed=TRUE)) num.vec=as.numeric(num.char[1:(length(num.char)-1)]) num.char # "B&quot...
2011 Sep 13
1
writing a loop using several list()-objects
...[[1]] [1] 2 5 8 > end[2] [[1]] [1] 4 7 9 I want to calculate sums of numbers in all start:end positions and list the output again, e.g. I can calculate the sum of the numbers occurring positions 2 till 4 of "sequence", i.e. between start[[2]][1] and end[[2]][1] using this code: sum(unlist(sequence[[2]])[unlist(Sfoot[[2]])[1]:unlist(end[[2]])[1]]) This code works perfectly fine but stops doing so if I put it into a loop: sums <- list() for(i in 1:length(start)) { for(j in 1:length(unlist(start[[i]]))) { sums[[i]][j] <- list(sum(unlist(sequence[[i]])[unlist(start[[i]])[j]:u...