Skip to content
Back to formatted view

Raw Message

Message-ID: <1341935884.99685.YahooMailNeo@web39403.mail.mud.yahoo.com>
Date: 2012-07-10T15:58:04Z
From: arun
Subject: Count of elements in coulmns of a matrix
In-Reply-To: <1341923464002-4635979.post@n4.nabble.com>

Hi,

Try this:

list1<-list(ABC=c(2,5),XYZ=c(3,4,4,2),PQR=c(4,5,3))
> lapply(list1,function(x) length(x))
$ABC
[1] 2

$XYZ
[1] 4

$PQR
[1] 3

?list2<-lapply(list1,function(x) length(x))
?dat2<-data.frame(list2)
?dat2
? ABC XYZ PQR
1?? 2?? 4?? 3
A.K.



----- Original Message -----
From: Rantony <antony.akkara at ge.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, July 10, 2012 8:31 AM
Subject: [R] Count of elements in coulmns of a matrix

Could you please tell me what is the function or method to get count of
elements in all the columns in a matrix ?

for eg :-

ABC? ? ? XYZ? ? PQR
------? ? ? -----? ?  ------
2? ? ? ? ? ? 3? ? ? ? ? ? 4
? ? ? ? ? ? ?  4? ? ? ? ?  5
5? ? ? ? ? ? 4? ? ? ? ?  3
? ? ? ? ? ? ? 2

Result will be like
ABC? ? ? XYZ? ? PQR
------? ? ? -----? ?  ------
2? ? ? ? ? ?  4? ? ? ? ? ? 3

Could you please help me ?

--
View this message in context: http://r.789695.n4.nabble.com/Count-of-elements-in-coulmns-of-a-matrix-tp4635979.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.