Displaying 20 results from an estimated 10000 matches similar to: "getting random integers"
2010 Sep 30
7
how to make list() return a list of *named* elements
If I combine elements into a list
b <- c(22.4, 12.2, 10.9, 8.5, 9.2)
my.c <- sample.int(round(2*mean(b)), 5)
my.list <- list(b, my.c)
the names of the elements seems to get lost in the process:
> str(my.list)
List of 2
$ : num [1:5] 22.4 12.2 10.9 8.5 9.2
$ : int [1:5] 11 8 6 9 20
If I explicitly name the elements at list-creation, I get what I want:
my.list <- list(b=b,
2009 Apr 29
3
how to word-wrap text in labels in plots?
c <- structure(c(2L, 2L, 1L, 3L, 4L, 2L, 3L, 2L, 3L, 2L, 5L), .Label = c("foo",
+ "bar", "a really really long variable label mostly here to show the need of word-wrapping text in labels",
+ "a not so important value", "baz"), class = "factor")
plot(c)
Is there a way to get the long variable labels to automatically wrap so that all
2012 Feb 25
5
which is the fastest way to make data.frame out of a three-dimensional array?
foo <- rnorm(30*34*12)
dim(foo) <- c(30, 34, 12)
I want to make a data.frame out of this three-dimensional array. Each dimension will be a variabel (column) in the data.frame.
I know how this can be done in a very slow way using for loops, like this:
x <- rep(seq(from = 1, to = 30), 34)
y <- as.vector(sapply(1:34, function(x) {rep(x, 30)}))
month <- as.vector(sapply(1:12,
2007 Nov 01
2
ploting a comparison of two scores, including the labels in the plot
Hello r-help!
I have data with two kind of ratings on status of 100 occupations. The
first kind of rating is on the percieved "objective" status that these
occupations have in society at large, and the second kind or rating is
on the status that the respondents think that these occuption *should*
have.
The ratings were originally integer values in the rage 1-9, but in the
current data,
2008 Feb 19
3
simple usage of "for"
Hi list
I have a data frame I would like to loop over. To begin with I would
like crosstabulations using the first variabel in the data frame,
which is called "meriter".
> table(meriter[[1]], meriter[[3]])
ja nej
Annan 0
2009 Apr 08
1
Student
Hi,
I have problem. In the function below (test and test2) i want the function
test not to print the variable data but i want the function test2 to use the
variable test$data.
This is the creation of the variable data:
> matrice=c(1:10)
> matrice=matrix(matrice,nrow=5,ncol=2)
This is the function test:
> test=function(data){
+ return(list(x=5,data=data))
+ }
This is the function
2008 Mar 03
3
Plot using colors
Dear R users,
I have a problem since I try to plot my datas with different colors.
plot(tvar, var, xlab="zeit [s]",ylab="Variation [%]", col = ifelse(var <=
varstability, 'green','red'))
this works well!
But since I add a type="l" to my plot, it will color all the plot with
green!!!
Is there any solution? I avoid to use teachingDemos.
Thanks.
--
2012 Mar 10
3
function input as variable name (deparse/quote/paste) ??
Hi all
Say I have a function:
myname=function(dat,x=5,y=6){
res<<-x+y-dat
}
for various input such as
myname(dat1)
myname(dat2)
myname(dat3)
myname(dat4)
myname(dat5)
how should I modify the 'res' line, to have new informative variable name
correspondingly, such as
dat1.res
dat2.res
dat3.res
dat4.res
dat5.res
stored in the workspace.
This is only an example of a complex
2012 Mar 02
3
speed up merge
Hello,
I have a nasty loop that I have to do 11877 times. The only thing that
slows it down really is this merge:
xx1 = merge(dt,ua_rd,by.x=1,by.y= 'rt_date',all.x=T)
Any ideas on how to speed it up? The output can't change materially (it
works), but I'd like it to go faster. I'm looking at getting around the
loop (not shown), but I'm trying to speed up the merge first.
2012 Mar 10
2
Issues in installing rgl in Mac OS 10.6.8
Dear All,
I am trying to install rgl on my mac notebook from the source file. I tried using: /usr/bin/R64 CMD INSTALL rgl_0.92.798.tar.gz and get the following
error message:
checking for X... no
configure: error: X11 not found but required, configure aborted.
ERROR: configuration failed for package ?rgl?
* removing
?/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl?
*
2009 Feb 17
1
frequency table for multiple variables
Hi r-help!
Consider the following data-frame:
var1 var2 var3
1 3 1 4
2 2 2 3
3 2 2 3
4 4 4 NA
5 4 3 5
6 2 2 3
7 3 4 3
How can I get R to convert this into the following?
Value 1 2 3 4 5
var1 0 3 2 2 0
var2 1 3 1 2 0
var3 0 0 4 1 1
TIA,
--
Hans Ekbrand (http://sociologi.cjb.net) <hans at
2009 Apr 08
1
read.spss, locale and encodings
I must be missing something obvious here:
According to the help page for read.spss, the reencode option is only
active when R is run under a UTF-8 locale.
read.spss can only import the SPSS file when run under a iso88591(5)
locale, under a UTF-8 locale I get:
Error in read.spss("wo.sav") : error reading system-file header
In addition: Warning message:
In read.spss("wo.sav")
2011 Mar 31
1
Cluster analysis, factor variables, large data set
Dear R helpers,
I have a large data set with 36 variables and about 50.000 cases. The
variabels represent labour market status during 36 months, there are 8
different variable values (e.g. Full-time Employment, Student,...)
Only cases with at least one change in labour market status is
included in the data set.
To analyse sub sets of the data, I have used daisy in the
cluster-package to create
2009 Apr 07
0
Converting a whole dataframe (including attributes) from latin1 to UTF-8
Hi list!
Short version: How do I convert a whole data.frame from latin1
encoding to utf8?
I get SPSS files with latin1 encoding. My OS is GNU/Linux and the
locale sv_SE.utf8, and I normally interface R with Emacs/ESS. I have
used the following hack to convert a data.frame in latin1 to utf8:
> Sys.setlocale(category = "LC_ALL", locale = "sv_SE.iso88591")
> foo <-
2003 Sep 14
1
title for plot contain 4 subplots
Hi,
I'm plotting 4 graphs on one page (2x2 matrix) but I cant seem to get
the title for the whole page right.
I'm doing:
op <- par(mfrow = c(2,2), pty="s")
hist(var$V2, breaks="FD",main="Euclidean Metric", xlab="Sum of 3NN ...
hist(var$V2, breaks="FD",main="Manhattan Metric", xlab="Sum of 3NN ...
hist(var$V2,
2012 Jul 05
3
Histogram
I have a column of 1000 datapoints from the normal distribution with mean 2
and variance 4. How can I get a histogram of these observations with 20
bins with each bin having 50 observations?
--
Thanks,
Jim.
[[alternative HTML version deleted]]
2003 Oct 28
1
stacking histograms
Hi,
I have a set of observations which are divided into two sets A and B.
I have some code that bins the dataset into 10 bins based on the max and
min of the observed values.
I would like to make a histogram of A & B using my calculated bins but
plot the distribution of B on top of A (like a stacked barplot). This is
possible since both sets A & B are binned using the same bin ranges.
2008 Apr 27
2
how to modify the histogram's frequencies
Hi:
I have been trying to figure out a simple way to plot an histogram whose
frequencies are modified by a factor (associated with each value).
Actually what I did was plotting each value with its modified
frequency(using plot($values, $frequency, type="h")), but it doesnt take
into account the probability distribution(which is necessary).
It will be very helpful from you any
2011 Jun 09
1
histogram - density on y axis and restriction to interval [0, 1]
Hello,
To indicate probability densities instead of counts on a histogram, I
specify freq = FALSE.
However, I expect that summing all top y coordinates over all the
intervals of the histogram will provide 1.
1)
v <- c(0.2885, 0.2988, 0.3139, 0.2615, 0.3179, 0.3163, 0.2583, 0.3052,
0.2527, 0.3147, 0.3235, 0.2408, 0.2480, 0.3108, 0.3577, 0.2829, 0.2694,
0.3275, 0.3314, 0.2639, 0.3076,
2011 May 26
1
Plotting device does not show all graphs
Dear All,
I am creating 4 plots (files) but I could see only 3. Here is a simple code
d=data.frame(age=rnorm(100,40,8),ht=rnorm(100,170,15))
tiff(file=paste("test","%03d",".tif",sep=""))
hist.data.frame(d)
datadensity(d)
par(mfrow=c(1,2),mar=c(3,3,3,3))
boxplot(d$age)
hist(age)
dev.off()
PDF works fine but png and tiff seems to miss the second