it needs a lappend function
lappend <- function(lst, obj) {
lst[[length(lst)+1]] <- obj
return(lst)
}
On Tue, Aug 5, 2014 at 10:59 PM, peter salzman
wrote:
> hi,
>
> this may be overkill but i have a general function that tabulates lists of
> anything. it works on vectors as in your e
hi,
this may be overkill but i have a general function that tabulates lists of
anything. it works on vectors as in your example.
the input is a list and the output is a list with 2 elements 1) list of
unique values and 2) a matching vector of counts. to that out[[1]][[k]]
occurs out[[2]][k] time
h
wrote:
> Alternatively, use sapply instead of lapply
>
> marieData <- list('30008'=c(1,0,1,0), '60008'=c(0,0,1,0), '90008'=c(0,0,1,0),
> '100007'=1, '130001'=c(0,1))
> marieData
> $`30008`
> [1] 1 0 1
007`
[1] 1
$`130001`
[1] 0 1
table(sapply(marieData, paste, collapse=''))
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Rui Barradas
Sent: Wednesday, 6 August 2014 8:49 a.m.
To: Marie-Pierre Sylvestre; r-help@r-project.org
Su
You can those vectors into character strings and pass them to table(). E.g.,
> d <- list(`30008`=c(1,0,1,0), `60008`=c(0,0,1,0), `90008`=c(0,0,1,0),
> `17`=1, `130001`=c(0,1), `130007`=c(1,0,1,0))
> dChar <- vapply(d, FUN=function(di)paste(di, collapse=" "), FUN.VALUE="")
> dTable <- table(d
Hello,
Maybe something like
table(unlist(lapply(HTNlist, paste, collapse = '')))
(Untested, it's a bad idea not to use ?dput to give a data example.)
Use
dput(head(HTNlist)) # paste the output of this in a mail
Hope this helps,
Rui Barradas
Em 05-08-2014 18:39, Marie-Pierre Sylvestre es
Dear R users,
I have a list of vectors (list is called HTNlist). Each vector is of length
1 to 4 and takes only 0 and 1 as values. E.g.
head(HTNlist)
$`30008`
[1] 1 0 1 0
$`60008`
[1] 0 0 1 0
$`90008`
[1] 0 0 1 0
$`17`
[1] 1
$`130001`
[1] 0 1
$`130007`
[1] 1 0 1 0
I would like to obtain
7 matches
Mail list logo