Displaying 20 results from an estimated 50000 matches similar to: "matrix"
2010 Feb 25
2
Rearranging entries in a matrix
I have a matrix, called data. I used the code below to rearrange the data such that the first column remains the same, but the y value falls under either columns 2, 3 or 4, depending on the value of z. If z=1 for example, then the value of y will fall under column 2, if z=2, the value of y falls under column 3, and so on.
data
x y z
[1,] 50 13 1
[2,] 14 8 2
[3,] 3 7 3
[4,] 4 16 1
[5,] 6
2010 Jan 20
1
Line Plot with Dates on X-axis
I am trying to generate a line graph with quarterly time buckets (with
nice labels) on the x-axis. The first block of code below will
generate the graph with nicely formatted x-axis labels, but the
"type=" and "col=" options are not recognized when factors are used
for the x-axis.
The second block, where the quarter values are mapped into dates, will
plot the line nicely but
2017 Dec 14
1
match and new columns
Hi Bill,
I put stringsAsFactors = FALSE
still did not work.
tdat <- read.table(textConnection("A B C Y
A12 B03 C04 0.70
A23 B05 C06 0.05
A14 B06 C07 1.20
A25 A23 A12 3.51
A16 A25 A14 2,16"),header = TRUE ,stringsAsFactors = FALSE)
tdat$D <- 0
tdat$E <- 0
tdat$D <- (ifelse(tdat$B %in% tdat$A, tdat$A[tdat$B], 0))
tdat$E <- (ifelse(tdat$B %in% tdat$A, tdat$A[tdat$C], 0))
2010 Jan 12
1
barplot: border color when stacked
Dear R-users,
I am using R version 2.10.1 under windows.
In a barplot, I want to mark one of the bars with a special border color.
For example:
barplot(c(3, 7, 11), border = c(NA, "red", NA))
But how to do this when the bars are stacked?
for example:
barplot(matrix(1:6, ncol=3)) # border of second bar (i.e. the one with total height = 7) should be red again, I try:
barplot(matrix(1:6,
2017 Dec 13
2
match and new columns
Thank you Rui,
I did not get the desired result. Here is the output from your script
A B C Y D E
1 A12 B03 C04 0.70 0 0
2 A23 B05 C06 0.05 0 0
3 A14 B06 C07 1.20 0 0
4 A25 A23 A12 3.51 1 1
5 A16 A25 A14 2,16 4 4
On Wed, Dec 13, 2017 at 4:36 PM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
> Hello,
>
> Here is one way.
>
> tdat$D <- ifelse(tdat$B %in% tdat$A,
2010 Jan 14
5
Better way than an ifelse statement?
Hello All,
I am trying to create a column of weights based off of factor levels
from another column. I am using the weights to calculate L scores.
Here is an example where the first column are scores, the second is my
"factor" and the third I want to be a column of weights. I can do
what I want with an ifelse statement (see below), but I am wondering
if anyone knows of a cleaner way
2009 Oct 13
2
Greater than less than in "ifelse"
I'm trying to categorize a continuous variable (yes, I know that's horrible, but I'm trying to reproduce some exercises from a textbook) and don't really know an efficient way to do this.
I have a data frame that looks like:
surv_time relapse sex log_WBC rx
1 35 0 1 1.45 0
2 34 0 1 1.47 0
3 32 0 1 2.20 0
4 32
2009 Dec 09
4
equivalent of ifelse
Hi,
Is there any equivalent for ifelse (except if (cond) expr1 else expr2) which takes an atomic element as argument but returns vector since ifelse returns an object of the same length as its argument?
x = c(1,2,3)
y = c(4,5,6,7)
z = 3
ifelse(z <= 3,x,y)
would return x and not 1
thanks
2009 Sep 17
3
How to generate a matrix where each row (or column) is the same vector?
Hi,
I can use the following code to generate a matrix, each column of
which is 'x'. But I have to specify '5' twice in the second command. I
am wondering if there is a better way to do it.
> x=1:10
> matrix(rep(x,5),nc=5)
> t(matrix(rep(x,5),nc=5))
Regards,
Peng
2013 Jul 02
2
Recoding variables based on reference values in data frame
I'm new to R (previously used SAS primarily) and I have a genetics data
frame consisting of genotypes for each of 300+ subjects (ID1, ID2, ID3,
...) at 3000+ genetic locations (SNP1, SNP2, SNP3...). A small subset of
the data is shown below:
SNP_ID SNP1 SNP2 SNP3 SNP4 Maj_Allele C G C A Min_Allele T A T G ID1
CC GG CT AA ID2 CC GG CC AA ID3 CC GG
nc
AA
2008 Feb 29
1
How to export tables in list separately using write.table or sink?
R users,
My intention is to take factors out of DF, create list of tables and
export these tables separately using write.table or sink function.
write.table writes tables out as DF:s, should I use sink instead?
Here is my example:
a <- data.frame( indx = 1:20,
var1 = rep(c("I20", "I40", "A50", "B60"), each=5),
2017 Jun 04
2
New var
Thank you Jeff and All,
Within a given time period (say 700 days, from the start day), I am
expecting measurements taken at each time interval;. In this case "0" means
measurement taken, "1" not taken (stopped or opted out and " -1" don't
consider that time period for that individual. This will be compared with
the actual measurements taken (Observed-
2017 Dec 14
0
match and new columns
Use the stringsAsFactors=FALSE argument to read.table when
making your data.frame - factors are getting in your way here.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Wed, Dec 13, 2017 at 3:02 PM, Val <valkremk at gmail.com> wrote:
> Thank you Rui,
> I did not get the desired result. Here is the output from your script
>
> A B C Y D E
> 1 A12 B03 C04 0.70 0 0
2017 Jun 04
0
New var
# read.table is NOT part of the data.table package
#library(data.table)
DFM <- read.table( text=
'obs start end
1 2/1/2015 1/1/2017
2 4/11/2010 1/1/2011
3 1/4/2006 5/3/2007
4 10/1/2007 1/1/2008
5 6/1/2011 1/1/2012
6 10/5/2004 12/1/2004
',header = TRUE, stringsAsFactors = FALSE)
# cleaner way to compute D
DFM$start <- as.Date( DFM$start, format="%m/%d/%Y" )
DFM$end
2011 Mar 18
1
predict lm doubt
Hello,
does anyone knows this predict is not resulting?
# lm predict
dfTestes3sitesCriptic$Velocity_corrected <- ifelse
(dfTestes3sitesCriptic$Season == "A" & dfTestes3sitesCriptic$BeforeAfter ==
"Before", (dfTestes3sitesCriptic$Velocity * mVel3ABefAfter), (ifelse
(dfTestes3sitesCriptic$Season == "Sp" & dfTestes3sitesCriptic$BeforeAfter ==
2010 Mar 03
1
Loop
Hi all,
Assume the following function that generate a random number.
z1<-function (n, eta)
{
wv <- runif(n)
wz <- (-1/eta) * log(wv)
wz
}
y <- z1(100,4)
mean(y)
I want to run this function say 1000 times and I want to count if
the mean(y) outside the following range 0.20 to 0.30.
How do I do it in R?
Thanks in advance
2009 Sep 29
3
Equivalent for Matematica function Which...
Dear All!
I'm looking for equivalent of Matematica function "Which" which works as
follows:
z = Which[x<10,0.3, 10<=x<20,0.5, 20<=x<100,1]
where x is a vector
I can replace it with custom function with set of ifelse but I'm looking
for simpler and faster (much faster) solution
best wishes
Jarek
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.
--
2017 Jun 04
0
New var
Since the number of choices is small (6), how about this?
Starting with Jeff's initial DFM:
DFM <- structure(list(obs = 1:6, start = structure(c(16467, 14710, 13152,
13787, 15126, 12696), class = "Date"), end = structure(c(17167,
14975, 13636, 13879, 15340, 12753), class = "Date"), D = c(700,
265, 484, 92, 214, 57), bin = structure(c(6L, 3L, 5L, 1L, 3L,
1L), .Label
2010 Feb 26
7
How to add a variable to a dataframe whose values are conditional upon the values of an existing variable
Hi everyone,
I am at my wits end with what I believe would be considered simple by a more experienced R user. I want to know how to add a variable to a dataframe whose values?are conditional?on the values of an existing?variable.?I can't seem to make an ifelse statement work?for my situation.?The existing variable?in my dataframe is?a character variable named DOW which contains abbreviated