Re: [R] help with counting how many times each value occur in eachcolumn

2007-08-10 Thread Gasper Cankar

Tom,

If all values (-100,0,-50) would be in every column then simple

apply(data,2,table)

would work. Even if there aren0t all values in every column you could
correct that and insert additional lines with all values for all columns 
like

data <- cbind(data,matrix(ncol=10,nrow=3,rep(c(-100,0,-50),10)))

and then do

apply(data,2,table)-1

to get correct results. But someone on a list can probably make much more
elegant solution.

Bye,

Gasper Cankar, PhD
Researcher
National Examinations Centre
Slovenia

-Original Message-
From: Tom Cohen [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 10, 2007 2:02 PM
To: r-help@stat.math.ethz.ch
Subject: [R] help with counting how many times each value occur in
eachcolumn

Dear list,
  I have the following dataset and want to know how many times each value
occur in each column.
   >data
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,] -100 -100 -100000000  -100
 [2,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100  
[3,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100  
[4,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100
 [5,] -100 -100 -100 -100 -100 -100 -100 -100 -100   -50
 [6,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100  
[7,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100  
[8,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100  
[9,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[10,] -100 -100 -100  -50 -100 -100 -100 -100 -100  -100 
[11,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[12,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[13,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[14,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[15,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[16,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[17,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100 
[18,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100
[19,] -100 -100 -100000000  -100
[20,] -100 -100 -100 -100 -100 -100 -100 -100 -100  -100
  The result matrix should look like
   -100 0 -50
[1]   20  
[2]   20
[3]   20
[4]   17
[5]   18
[6]   18
[7]   18  and so on 
[8]
[9]
[10]
  
How can I do this in R ?
  Thanks alot for your help,
Tom

   
-

Jämför pris på flygbiljetter och hotellrum:
http://shopping.yahoo.se/c-169901-resor-biljetter.html
[[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
and provide commented, minimal, self-contained, reproducible code.


[R] issue with plot (type="h")

2006-02-22 Thread Gasper Cankar
Hello everyone.

For reasons too long to explain I wanted to do plots similar to histograms with 
plot(type="h"). 
I ran into a problem - if I set line width too high, histogram isn't accurate 
anymore.

For example:

par(lend=2)
plot(c(2,4,3,2),ylim=c(0,5), type="h")
abline(h=3)

Column 3 appears just as high as it should. But if I do

par(lend=2)
plot(c(2,4,3,2),ylim=c(0,5), type="h",lwd=100)
abline(h=3)

then columns become too high. Can I correct the problem or is there another way 
to display my data correctly?

Thanks for help,



Gašper Cankar 
National Examinations Centre, 
Slovenia

__
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


[R] name of object from character vector

2005-03-11 Thread Gasper Cankar
Hello everyone!

A simple question (I'm not sure about the answer):

How can I give a name to my data.frame from a character vector of names? 
For example, each data.frame is a table of results for a subject and I have a 
vector of subject names like

b <- c("math", "geography", "history")

How do I create a data.frame named "math" by calling b[1]? 

I'm importing data via RODBC in one big loop for all subjects and
I want them separated so I'll be able to load them one at a time later on. 

Thanks for your help,

Gasper


Gasper Cankar
National Examinations Centre
Slovenia
+386 1 54 84 682
gasper.cankarATric.si

__
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