Suppose I had a 1-by-12 matrix and I wanted to resize it to a 4-by-3 matrix. How could I do this?
My current solution is kind of ugly:
for n=1:length(mat)/3
out(n,1:3) = mat((n-1)*3+1:(n-1)*3+3);
end
Is there a better way to do this?
...
I'm running into difficulties reshaping a large dataframe. And I've been relatively fortunate in avoiding reshaping problems in the past, which also means I'm terrible at it.
My current dataframe looks something like this:
unique_id seq response detailed.name treatment
a N1 123.23 descr. of N1 T1
a ...
I have the following variables in a data frame
[1] "Type" "I.alt" "idx06" "idx07" "idx08" "farve1" "farve2"
If I do
dm <- melt(d, id=c("Type","I.alt"))
i get theese variables
"Type" "I.alt" "variable" "value"
where "idx06", "idx07", "idx08", "farve1", "farve2" is represented in "variable".
But what I really want is...
Hi
I have a dataframe that I want to reshape; my reshape code:
matchedlong <- reshape(matched, direction = 'long',
varying = c(29:33, 36:3943),
v.names = c("Math34", "TFCIn"),
times = 2006:2009, idvar = "schoolnum")
in "matched" columns 36 to 39 are logical (TRUE FAL...
Hi there,
I've been looking around for some data about naming trends in USA. I managed to get top 1000 names for babies born in 2008. The data is formated in this manor:
male.name n.male female.name n.female
Jacob 22272 Emma 18587
Michael 20298 Isabella 18377
Ethan 20004 Emily 17217
Joshua 18924 Madison 16853
Daniel 18717 Ava 168...
I have data in a mysql table in long / tall format (described below) and want to convert it to wide format. Can I do this using just sql?
Easiest to explain with an example. Suppose you have information on (country, key, value) for M countries, N keys (e.g. keys can be income, political leader, area, continent, etc.)
Long format has 3 ...
I have a 3d matrix (n-by-m-by-t) in MATLAB representing n-by-m measurements in a grid over a period of time. I would like to have a 2d matrix, where the spatial information is gone and only n*m measurements over time t are left (ie: n*m-by-t)
How can I do this?
...
I've encountered a strange behaviour in cast/melt from Hadley Wickham's reshape package. If I cast a data frame, and then try to melt it, the melt comes out wrong. Manually unsetting the "df.melt" class from the cast dataframe lets it be melted properly.
Does anyone know if this is intended behaviour, and if so, what is the use case whe...
I have a data frame with gaps like this:
Var1 Var2 Var3
1 NA NA NA
2 NA NA NA
3 NA NA NA
4 NA 0.06703 NA
5 NA 0.08639 NA
6 NA 0.19023 0.02322
7 NA 0.31764 0.08058
8 NA 0.44426 0.15081
9 ...
I have a data frame where one particular column has a set of specific values (let's say, 1, 2, ..., 23). What I would like to do is to convert from this layout to the one, where the frame would have extra 23 (in this case) columns, each one representing one of the factor values. The data in these columns would be booleans indicating whet...
This seems to be a very common problem of mine:
data = [1 2 3; 4 5 6];
mask = [true false true];
mask = repmat(mask, 2, 1);
data(mask) ==> [1; 4; 3; 6]
What I wanted was [1 3; 4 6].
Yes I can just reshape it to the right size, but that seems the wrong way to do it. Is there a better way? Why doesn't data(mask) return a matrix whe...
In R, I have a data frame with columns for Seat (factor), Party (factor) and Votes (numeric). I want to create a summary data frame with columns for Seat, Winning party, and Vote share. For example, from the data frame
df <- data.frame(party=rep(c('Lab','C','LD'),times=4),
votes=c(1,12,2,11,3,10,4,9,5,8,6,15),
...
Dear overflowers,
I have a rather large dataset in a long format where I need to count the number of instances of the ID due to two different variables, A & B. E.g. The same person can be represented in multiple rows due to either A or B. What I need to do is to count the number of instances of ID which is not too hard, but also count t...
I'd like to melt the dataframe so that in one column i have dates in a second i have username as the variable and finally the value.
I'm getting this error:
Error in as.Date.numeric(value) : 'origin' must be supplied
and while I understand the error I'm not exactly sure how to get around it.
A small sample of the data is:
structure(...
I am trying to use the functionality of the reshape function available in MATLAB in Java. Are there any implementations of reshape available in Java?
...
Hello,
I do not want to use 3rd party controls because I would have to buy a suite for justing using one control...
So is there any chance I can arrange 3 entities: Subject, Grade and Pupil in that way on a simple DataGrid to show Pivot data like:
...........Math....Sports....
M.Kramer...A.......C.........
B.Jonson...D.......A........
I wonder how could is possible to make custom shape key on android keyboard. To create custom keyboard is relatively easy, but what needs to be done to create new buttons. They also need to respond with all events as normal keyboard.
Any ideas where to start?
...
I'm using reshape in R to compute aggregate statistics over columns of a data.frame. Here's my data.frame:
> df
a a b b ID
1 1 1 1 1 1
2 2 3 2 3 2
3 3 5 3 5 3
which is just a little test data.frame to try and understand the reshape package. I melt, and then cast, to try and find the mean of the as and the bs:
> melt(df, id = "ID...
I need to take a data.frame in the format of:
id1 id2 mean start end
1 A D 4 12 15
2 B E 5 14 15
3 C F 6 8 10
and generate duplicate rows based on the difference in start - end. For example, I need 3 rows for the first row, 1 for the second, and 2 for the third. The start and end fields should be in...
I have glad to hear that there is an updated version for reshape2 package.
I installed the package, but discovered that ggplot2 package still insist to have the reshape package, rather than the reshape2 package, as I manually removed the reshape package and then ggplot2 cannot run.
Anything I can do to fix it? Thanks!
...