Displaying 20 results from an estimated 40000 matches similar to: "Help with reshape/reShape and indexing"
2011 Oct 01
2
Help with cast/reshape
I realize that this is terribly basic, but I just don't seem to see it at this moment, so I would very much appreciate your help.
How shall I transform this dataframe:
> df1
? Name Index Value
1??? a???? 1?? 0.1
2??? a???? 2?? 0.2
3??? a???? 3?? 0.3
4??? a???? 4?? 0.4
5??? b???? 1?? 2.1
6??? b???? 2?? 2.2
7??? b???? 3?? 2.3
8??? b???? 4?? 2.4
into this dataframe:
> df2
??? Index?
2008 Feb 08
1
reshape question
I know there are a lot of reshape questions on the mailing list, but I
haven't been able to find an answer to this particular issue.
I am trying to get a datafame structured like this:
> sub <- rep(1:5)
> ta1 <- rep(1,5)
> ta2 <- rep(2,5)
> tb1<- rep(3,5)
> tb2 <- rep(4,5)
> DF <- data.frame(sub,ta1,ta2,tb1,tb2)
> DF
sub ta1 ta2 tb1 tb2
1
2009 Nov 22
2
Help with indexing
Dear R Helpers,
I am missing something very elementary here, and I don't seem to get it from the help pages of the ave, seq and seq_along functions, so I wonder if you could offer a quick help.
To use an example from an earlier post on this list, I have a dataframe of this kind:
dat = data.frame(name = rep(c("Mary", "Sam", "John"), c(3,2,4)))
dat$freq =
2011 Feb 06
3
manipulate dataframe
Hello,
Can someone give me hint to change a data.frame.
I want to split a column in more columns depending on the value of a other
column.
Thanks for the reaction,
Andre
Example:
> dat
x1 x2
1 1 a
2 1 b
3 1 c
4 2 d
5 2 e
6 2 f
7 3 g
8 3 h
9 3 i
in
> dur
d1 d2 d3
1 a d g
2 b e h
3 c f i
[[alternative HTML version deleted]]
2013 Jan 11
2
Merging list of dataframes with reshape merge_all
Hi,
I'd like to merge mutliple dataframes from a list of dataframes by some common
columns. The approach for simply merging 2 dataframes is working with:
merge(df1,df2,by=c("col1","col2","col3"),all=TRUE)
For mutliple dataframes in a list I try to use the merge_all command
from the package reshape.
The documentation states that the command takes a list of
2013 Sep 09
1
windowing
Is there a package or a command that does window aggregation like
select
sum(col1) over
(partition by col2, col3 order by col4
rows between unbounded preceding and current row) as sum1
from table1 ;
the above is Netezza syntax, but Postgre has same capability.
Stephen B
[[alternative HTML version deleted]]
2004 Apr 03
3
Seeking help for outomating regression (over columns) and storing selected output
Hello,
I have spent considerable time trying to figure out that which I am about to describe. This included searching Help, consulting my various R books, and trail and (always) error. I have been assuming I would need to use a loop (looping over columns) but perhaps and apply function would do the trick. I have unsuccessfully tried both.
A scaled down version of my situation is as follows:
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
2010 Aug 06
2
stats::reshape question
Hello,
A quick question for my edification. When I run the following (R 2.8.1 on
Microsoft Windows):
> d = data.frame(x1=c(1,2),x2=c(3,4),y1=c(5,6),y2=c(7,8))
> reshape(d,varying=c("y1","x1","y2","x2"),v.names=c("y","x"),dir="long")
I found myself surprised by the results--the column labeled "y" is actually
2012 Jul 24
3
Simple reshape problem I am completely missing
I seem to be doing something really stupid or missing something really obvious but what?
I have a simple three column data.frame that I would like to reshape to wide preferably using reshape2.
An example from http://stackoverflow.com/questions/9617348/reshape-three-column-data-frame-to-matrix looked perfect except I wanted a data frame but it seemed okay. I just changed acast to dcast and it
2010 Jan 28
1
question about reshape
Hello everyone,
I have a bit of a problem with reshape function in R.
I have simulated some normal data, which I have saved in 4 vectors.
y.1,y.2,y.3,y.4 which I combined a dataset:
dataset<cbind(y1,y2,y3,y4). I have also generated some subject id number,
and denoted that by subject.
So, my dataset looks like this:
subject y.1 y.2 y.3 y.4
[1,] 1 20.302707
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
2009 Sep 18
1
merging data frames with matrix objects when missing cases
Hi,
I have faced a problem with the merge() function when trying to merge
two data frames that have a common index but the second one does not
have cases for all indexes in the first one. With usual variables R
fills in the missing cases with NA if all=T is requested. But if the
variable is a matrix R seems to insert NA only to the first column of
the matrix and fill in the rest of the columns by
2010 Jun 18
2
help with reshape is needed again!
hi, folks:
i need to transpose the following data:
gene tissue patient1 patient2 patient3.....
---------------------------------------------
gene1 breast 10 100 1
gene2 breast 20 200 4
gene3 breast 30 50 5
gene4 breast 40 400 9
................................
to the
2020 Sep 10
2
aplicar codigo
Yo copio y pego este código y me sale correctamente. Se me ocurre que
pueda deberse a la versión de R ¿cuál usas?
El 10/09/2020 a las 17:51, Samura . escribió:
> Gracias por las respuestas.
>
> Probé lo de hacer la función y no me salía. Pensaba que hacía algo mal.
> Ahora con el código de Marcelino tampoco me sale.
>
> col1 <- c('x1', 'x2', 'x11',
2017 Jul 05
4
Help with reshape/reshape2 needed
Hi all:
I'm struggling with getting my data re-formatted using functions in
reshape/reshape2 to get from:
1957 0.862500000
1958 0.750000000
1959 0.300000000
1960 0.287500000
1963 0.675000000
1964 0.937500000
1965 0.025000000
1966 0.387500000
1969 0.087500000
1970 0.275000000
1973 0.500000000
1974 0.362500000
1976 0.925000000
1978 0.712500000
1979 0.337500000
1980 0.700000000
1981 0.425000000
2011 Oct 24
1
using predict.lm() within a function
I've written a simple function to draw a regression line in a plot and
annotate the line showing the slope
with a label. It works, as I'm using it, when the horizontal variable
is 'x', but gives incorrect results otherwise.
What's wrong?
# simple function to show the slope of a line
show.beta <- function(model, x="x", x1, x2, label, col="black", ...)
2020 Sep 10
3
aplicar codigo
Hola,
me gustar?a hacer algo como en el siguiente ejemplo
A un df a?adirle una columna que es la transformaci?n de otra,
en plan a todo lo que sea x1, x2, x3 lo llamo prueba 1
todo lo que sea x4,x5,x6 lo llamo prueba 2
el resto de x las dejo como est?n.
Ser?a algo as?
col1 <- c('x1', 'x2', 'x11', 'x1','x33', 'x1','x4', 'x5',
2008 Jun 09
1
Plot Coloured Triangle
Hi there,
I'd like to plot a triangle with each point having a certain color defined and
fill it with the interpolated values.
The following code shall represent somehow, three points with x,y, and the
"amount" of red for example...
point1 <- c(1.1, 1.7, 255)
point2 <- c(2.2, 1.5, 180)
point3 <- c(1.8, 2.2, 60)
can anybody give me a hint which methods to use to realize
2020 Sep 10
5
aplicar codigo
Hola:
Como dice Carlos, algo así, por ejemplo:
transforma <- function(df) sapply(df, function(x)
ifelse(x%in%c("x1","x2","x3"),
"prueba1",ifelse(x%in%c("x4","x5","x6"),"prueba2",x)))
> transforma(df1)
col1
[1,] "prueba1"
[2,] "prueba1"
[3,] "x11"
[4,]