Displaying 20 results from an estimated 10000 matches similar to: "Rearranging entries in a matrix"
2010 Feb 28
4
Reducing a matrix
I wish to rearrange the matrix, df, such that all there are not repeated x values. Particularly, for each value of x that is reated, the corresponded y value should fall under the appropriate column. For example, the x value 3 appears 4 times under the different columns of y, i.e. y1,y2,y3,y4. The output should be such that for the lone value of 3 selected for x, the corresponding row entries
2002 Nov 26
1
Reshape by multiple variables
Dear list
I'm using the reshape command and want to reshape a wide data set to a
long one
e.g. I have the variables y1,y2,y3,age1,age2,age3,sex,ethnic
I want my new long data set to consist of the variables y (which has
been created from y1,y2,y3), age (which has been created from
age1,age2,age3), sex and ethnic
I have tried to use the command:
2011 Jul 11
2
best way to aggregate / rearrange data.frame with different data types
Hi,
I have a data.frame that looks like this:
Subject <- c(rep(1,4), rep(2,4), rep(3,4))
y <- rnorm(12, 3, 2)
gender <- c(rep("w",4), rep("m",4), rep("w",4))
comment <- c(rep("comment A",4), rep("comment B",4), rep("comment C",4))
data <- data.frame(Subject,y,gender,comment)
data
Subject y gender
2011 Oct 14
3
Split a list
I have a list of dataframes i.e. each list element is a dataframe with three columns and differing number of rows. The third column takes on only two values. I wish to split the list into two sublists based on the value of the third column of the list element.
Second issue with lists as well. I would like to reduce each of the sublist based on the range of the second column, i.e. if the range of
2005 Jan 21
2
Selecting a subplot of pairs
Hello,
I'm trying to plot a set of 3 dependant variables (y) against 4
predictors (x) in a matrix-like plot, sharing x- an y-axis for all the
plot on the same column/line :
y1/x1 y1/x2 y1/x3 y1/x4
y2/x1 y2/x2 y2/x3 y2/x4
y3/x1 y3/x2 y3/x3 y3/x4
In fact, this plot is a rectangular selection of the result of pairs(),
limited to the relations between x's and y's
2011 Nov 15
5
Convert back to lower triangular matrix
Given a vector;> ab = seq(0.5,1, by=0.1)> ab[1] 0.5 0.6 0.7 0.8 0.9 1.0
The euclidean distance between the vector elements is given by the lower triangular matrix > dd1 = dist(ab,"euclidean")> dd1 1 2 3 4 52 0.1 3 0.2 0.1 4 0.3 0.2 0.1 5 0.4 0.3 0.2 0.1 6 0.5 0.4 0.3 0.2 0.1
Convert the lower triangular matrix to a full
2011 Aug 15
1
update() ignores object
Hi all,
I'm extracting the name of the term in a regression model that
dropterm specifies as the least significant one, and I'm assigning
this name to an object. However, when I use update(), it ignores this
object. Is there a way I can make it not ignore it? A reproducible
example is below:
> lm(x1~1+y1*y2+y3+y4,data=anscombe)->my.lm
>
2008 Dec 29
4
Merge or combine data frames with missing columns
Hi R-experts,
suppose I have a list with containing data frame elements:
[[1]]
(Intercept) y1 y2 y3 y4
-6.64 0.761 0.383 0.775 0.163
[[2]]
(Intercept) y2 y3
-3.858 0.854 0.834
Now I want to put them into ONE dataframe like this:
(Intercept) y1
2011 Jan 19
2
Reshape
Hi - I'm up against a complicated reshape problem. I have data of the form
X1,Y1,hr1,hr2,hr3
X1,Y2,hr1,hr2,hr3
X1,Y3,hr1,hr2,hr3
X2,Y1,hr1,hr2,hr3
X2,Y2,hr1,hr2,hr3
X2,Y3,hr1,hr2,hr3
where X and Y are factors and the hr(1,2,3) are values. I need it as
,X1, X2
Y1,hr1,hr1
Y1,hr2,hr2
Y1,hr3,hr3
Y2,hr1,hr1
Y2,hr2,hr2
Y2,hr3,hr3
..,
Any hints? I've been at it for hours.
p
--
View
2008 Aug 13
1
summary.manova rank deficiency error + data
Dear R-users;
Previously I posted a question about the problem of rank deficiency in
summary.manova. As somebody suggested, I'm attaching a small part of
the data set.
#***************************************************
"test" <-
structure(.Data = list(structure(.Data = c(rep(1,3),rep(2,18),rep(3,10)),
levels = c("1", "2", "3"),
class =
2010 Oct 21
1
All other variables in upper scope arg for stepAIC
Hi - I am trying to substitute for "the_other_y" in the code below. I want
y2 and y3 to be there when i is 1, y1 and y3 to be there when i is 2 and y1
and y2 to be there when i is 3. I'm sure it's to do with what format the
data should be in and I've tried alldata[,-i], but it fits all the columns
of alldata except i rather than each column one at a time. I've tried
2010 Mar 12
2
Handling repeated values differently
mat is a matrix with X and Y values.
> mat
X Y
[1,] 56 20
[2,] 56 21
[3,] 2 50
[4,] 3 46
[5,] 18 77
[6,] 57 12
[7,] 57 36
[8,] 95 45
[9,] 65 23
[10,] 33 25
[11,] 33 98
[12,] 63 96
[13,] 66 75
[14,] 99 54
[15,] 78 65
[16,] 75 69
[17,] 54 68
[18,] 54 67
[19,] 0 22
[20,] 14 74
[21,] 15 52
[22,] 46 10
[23,] 6 20
[24,] 6 30
As you can see, some of the X values repeat. I wish
2010 Jul 12
3
Continuing on with a loop when there's a failure
Hi R sages,
Here is my latest problem. Consider the following toy example:
x <- read.table(textConnection("y1 y2 y3 x1 x2
indv.1 bagels donuts bagels 4 6
indv.2 donuts donuts donuts 5 1
indv.3 donuts donuts donuts 1 10
indv.4 donuts donuts donuts 10 9
indv.5 bagels donuts bagels 0 2
indv.6 bagels donuts bagels 2 9
indv.7 bagels donuts bagels 8 5
indv.8 bagels donuts bagels 4 1
indv.9
2005 Apr 04
1
custom loss function + nonlinear models
Hi all;
I'm trying to fit a reparameterization of the
assymptotic regression model as that shown in
Ratkowsky (1990) page 96.
Y~y1+(((y2-y1)*(1-((y2-y3)/(y3-y1))^(2*(X-x1)/(x2-x1))))/(1-((y2-y3)/(y3-y1))^2))
where y1,y2,y3 are expected-values for X=x1, X=x2, and
X=average(x1,x2), respectively.
I tried first with Statistica v7 by LS and
Gauss-Newton algorithm without success (no
2007 Dec 06
2
How can I plot this graph
Hi,
I am having trouble plotting the graph I need given the follow kind of data
> xxx <- data.frame(
"x"=c(1,2,3,4,5),
"y1"=c(2,4,3,5,6),
"y2"=c(3,4,6,3,1),
"y3"=c(1,3,5,7,3),
"z1"=c(1,NA,3,5,NA),
"z2"=c(2,NA,4,6,NA) )
> xxx
x y1 y2 y3
2010 Nov 19
3
assigment
Hello R Users,
I have vectors
x <- c("a2","b7","c8")
y1 <- c(1,2,3,2)
y2 <- c(4,2,7,5,4,3,8)
y3 <- c(1:10)
and I want to assign values form vector y1 to a new variable which
name comes from the 1st value of the vector x etc. How to do it using
only vector x. As a result I should have:
a2 <- y1
b7 <- y2
c8 <- y3
More general problem: I have 2 txt
2007 Dec 02
3
Help with a Loop
I am having trouble getting a loop to work for the following problem. Any
help would be much appreciated. Thanks.
I need to find the slope and intercept from the linear regression of Drug
Level on Day by Participant. There are a total of 37 Participants. I need to
store the Participant, Label, Slope, and Intercept in a new data frame.
This data is ordered by Participant number 37 total
2005 Dec 08
2
how to change a dataframe with characters to a numeric matrix?
hi netters,
i have a dataframe TEST like this:
Y1 Y2 Y3
X1 4 7 8
X2 6 2 Z
X3 8 0 1
i would like to change it to a numeric matrix, replacing "Z" with NA
Y1 Y2 Y3
X1 4 7 8
X2 6 2 NA
X3 8 0 1
i've tried the function data.matrix but it didn't work. is there any easy
way to do this?
thanks a lot!
2007 Nov 14
1
Changing the text in the strips of lattice plots and y axis
Dear R-helpers,
I am sorry for asking something I know has been
asked before, I have tried different combinations in
the strip function without success...
I am using version 2.5.1 and work on a PC.
I have barcharts generated from the following
formula:
barchart(y1+y2+y3~x | g)
I need to change the names of the variables y1,y2 or
y3 that currently appear in the strips, I have two
2017 Jun 25
2
Writing my 3D plot function
Hi all,I had a question last week on asking for a function that will help me draw three different circles on x,y,z axis based on polar coordinates (Each X,Y,Z circle are coming from three independent measurements of 1-360 polar coordinates). It turned out that there ?is no such function in R and thus I am trying to write my own piece of code that hopefully I will be able to share. I have spent