Displaying 20 results from an estimated 30000 matches similar to: "How to stack row vector on top of each other?"
2013 Feb 07
4
Sourcing my file does not print command outputs
I looked at the documentation of source() and summary(), and I could not
find the reason why calling something like:
> summary(resamps)
from the command line, works (it prints the summary)
whereas calling
summary(resampls)
from a file that I source with source("my_file.r") does not print anything.
How can I get summary(resamps) to print when I source a file with this
command?
2007 Nov 15
1
HELP: How to subtract a vector out of each row of a matrix or array
Hi All,
I am having great trouble doing something pretty simple.
Here is what I did:
> x <- read.table("clipboard")
> dim (x)
[1] 126 10
> typeof(x)
[1] "list"
> w <- array(x)
> typeof(w)
"list"
Q1: How come after constructing an array out of the list, the type of
the array is still "list"?
> w <- as.array(x)
Error in
2010 Dec 06
5
How can I refer to actual (n) and previous (n-1) elements in a vector?
Hello,
How can I apply a function on a vector that refers to actual (n) and previous elements in the vector (e.g. n-1)?
For example:
I would like to calculate the sum of (n-1) + n for each element of a vector and get a vector as a result.
Besides others I tried this:
v<-c(3,6,8,1,1,3,9,5,6,3)
for (i in 1:NROW(v)){a[i]<-a[i-1]+a[i]}
I would like to get this result:
2012 Jun 19
2
matchit - can I weight the parameters?
This may be a really obvious question but I just can't figure out how to do it.
I have a small dataset that I am trying to compare to some controls. It is essential that the controls are matched on Cancer Stage (a numerical factor between 1 and 4), and then ideally on Age (integer), Gender (factor), Performance Status(factor).
I'm using matchit to try and do this, but it seems to give
2009 Apr 15
2
problem with read.table
Hi all,
I've simple code to read a file (verify.txt in the same directory as the script file) but when I run this I get
"Error in eval(expr, envir, enclos) : object "y" not found".
data_model.df = read.table("./verify.txt", header=TRUE, nrows=10);
f <- lm(y ~ x)
Could someone pls tell me what's wrong with this code?
Sincere thanks!
2012 Aug 23
3
Concatenating data frames in R versus SAS
I am trying to concatenate 2 datasets that don't have exactly the same
column.
In SAS I did: data summary;
set agency prop;
run;
No problem
in R I get error message
summary <-rbind(agency,prop)
Error in match.names(clabs, names(xi)) :
names do not match previous names
But when I use rbin.fill, that overwrites the second file w/ first one.
Is there a way to replicate the sas process
2011 Jul 19
2
Taking all "complete" diagonals of a matrix
Hi R-Help!
I am trying to find a nicer way of extracting all the "complete" diagonals
of a matrix. I am working with very large matrices that have many more rows
than columns. I want to be able to extract each of the diagonals that are
as long as the number of columns in the matrix. I have written a rather
ugly function that presently does the job. It illustrates what I am trying
to
2011 Dec 15
1
how to draw random numbers from many categorical distributions quickly?
Dear R helpers,
I have a question about drawing random numbers from many categorical
distributions.
Consider n individuals, each follows a categorical distribution defined
over k categories.
Consider a simple case in which n=4, k=3 as below
catDisMat <-
rbind(c(0.1,0.2,0.7),c(0.2,0.2,0.6),c(0.1,0.2,0.7),c(0.1,0.2,0.7))
outVec <- rep(NA,nrow(catDisMat))
for (i in 1:nrow(catDisMat)){
2012 Jun 12
6
Attempting to update from R 2.14 to 2.15
I am very new to Linux so I probably am doing something stupid but I cannot seem to update to R 2.15
Using Ubuntu 12.02 Precise Penguin
I realise that debian packages are not updated regularly so I tried to follow the insructions at the R-site
So far, I have modified /etc/apt/sources.list to read
## R CRAN added 2012-06-12
deb http://probability.ca/cran/bin/linux/debian squeeze-cran/
Issued
2011 Mar 01
3
Difference in numeric Dates between Excel and R
Hello. I am using some dates I read in excel in R. I know the excel origin
is supposed to be 1900-1-1. But when I used as.Date with origin=1900-1-1 the
dates that R reported me where two days ahead than the ones I read from
Excel. I noticed that when I did in R the following:
> as.Date("2011-3-4")-as.Date("1900-1-1")
Time difference of 40604 days
but if I do the same
2012 Nov 15
3
Can you have a by variable in Lag function as in SAS
Hello,
I want to use lag on a time variable but I have to take date into
consideration ie I don't want days to overlap ie:
I don't want my first time of today to match my last time of yeterday.
In SAS I would use :
data x;
set y;
by date tim;
previous=lag(tim);
if first.date then
do;
previous=.;
end;
run;
How can I do something similar in R? I can't find
2013 Feb 26
2
merging or joining 2 dataframes: merge, rbind.fill, etc.?
#I want to "merge" or "join" 2 dataframes (df1 & df2) into a 3rd
(mydf). I want the 3rd dataframe to contain 1 row for each row in df1
& df2, and all the columns in both df1 & df2. The solution should
"work" even if the 2 dataframes are identical, and even if the 2
dataframes do not have the same column names. The rbind.fill function
seems to work. For
2012 Aug 14
2
What package to use to calculate odds ratio and the confidence interval?
Hi list,
I am trying to calculate the sensitivity, specificity, and odds ratio(and
confidence interval).
Say, my data looks like this
42.53, 37.56, 40.51, 32.67, 38.19, 81.74, 41.55, 68.94, 59, 63, 54.13,
48.85, 50.46, 51.78
Is there any packages in R that does this? Espeically the odds ratio
confidence interval.
Mike
[[alternative HTML version deleted]]
2012 Jun 12
4
How to index a matrix with different row-number for each column?
here's my question: suppose I have a matrix:
mt<-matrix(1:12,ncol=6)
now I have a vector
vt<-c(1,2,2,2,1,2)
which means I want to get:
the 1st row for column1;
the 2nd row for column2;
the 2nd row for column3;
the 2nd row for column4;
...
that what I want is this vector:
1,4,6,8,9,12
Does anyone know how to do this fast?
I know I can use for-loop to travel all columns,but
2008 Sep 10
4
re flecting a line
Suppose x and y are numeric vectors of the same length.
plot(x,y) #scatterplot
lmObj1 <- lm(y~x) # best fit line
abline(lmObj1) # good
lmObj2 <- lm(x~y) #get best fit but with axes interchanged
abline(lmObj2) # not what I want. I want the correct line, drawn on the same
graph, but with
# response and predictor variables interchanged
One way to proceed would be to
2010 Feb 25
5
Plotting 15 million points
Hi All
I have a vector of about 15 million numbers which I would like to
plot. The goal is the see the distribution. I tired the usual steps.
1. Histogram : never gets complete my window freezes w/out log base 10
2. Density : I first calculated the kernel density and then plotted
it which worked.
It would be nice to superimpose histogram with density but as of now I
am not able to get this
2013 Feb 20
2
Why R simulation gives same random results?
Hi, list
I am doing 100,000 iterations of Bayesian simulations.
What I did is I split it into 4 different R sessions, each one runs 25,000
iteration. But two of the sessions gave the simulation result.
I did not use any set.seed(). What is going on here?
Thanks,
Mike
[[alternative HTML version deleted]]
2012 Feb 21
4
removing particular row from matrix
I have some data set which has some values -999.000 & I would like to remove
whole row of this kind of values.
e.g
a<-matrix(c(1,2,3,4,4,5,6,6,-999.99,5,9,-999.00),nrow=4)
a<-
[,1] [,2] [,3]
[1,] 1 4 -999.99
[2,] 2 5 5.00
[3,] 3 6 9.00
[4,] 4 6 -999.00
expected answer
[,1] [,2] [,3]
[1,] 2 5 5.00
[2,] 3 6 9.00
I
2009 Oct 20
2
Problems importing Unix SAS .ssd04 file to R (Win)
Hello,
I'm trying to import a SAS file made using SAS on Unix. Currently I'm
using SAS on Windows and I'm trying to import that .ssd04 file to R.
The file name of the file is testfile.ssd04 and it is located in
'M:\sasuser'. I'm using Windows XP and R 2.91. Basically what I'm
doing is
############ r code ##############
> library(foreign)
> sashome <-
2013 Feb 12
7
Is there a neat R trick for this?
Hello all,
given two vectors X and Y I'd like to receive a vector Z which
contains, for each element of X, the index of the corresponding
element in Y (or NA if that element isn't in Y).
Example:
x <- c(4,5,6)
y <- c(10,1,5,12,4,13,14)
z <- findIndexIn(x, y)
z
[1] 5 3 NA
1st element of z is 5, because the 1st element of x is at the 5th position in y
2nd element of z is 3,