reshape

Why reshape2's Melt cannot capture rownames in the transformation?

倖福魔咒の 提交于 2019-12-31 10:04:40
问题 I have the following data: Cubn 3.71455160837536 0.237454645363458 Gm9779 2.56051657980096 0.20850752817264 Apod 3.51796703048962 0.195999214485821 What I want to do is to create the 'melted' data such that it gives this var1 var2 value 1 FOO Cubn 3.7145516 2 FOO Gm9779 2.5605166 3 FOO Apod 3.5179670 4 BAR Cubn 0.2374546 5 BAR Gm9779 0.2085075 6 BAR Apod 0.1959992 But why this failed? library("reshape2"); dat <-read.table("http://dpaste.com/1446132/plain/",header=FALSE) rownames(dat) <- dat[

Why reshape2's Melt cannot capture rownames in the transformation?

倖福魔咒の 提交于 2019-12-31 10:04:34
问题 I have the following data: Cubn 3.71455160837536 0.237454645363458 Gm9779 2.56051657980096 0.20850752817264 Apod 3.51796703048962 0.195999214485821 What I want to do is to create the 'melted' data such that it gives this var1 var2 value 1 FOO Cubn 3.7145516 2 FOO Gm9779 2.5605166 3 FOO Apod 3.5179670 4 BAR Cubn 0.2374546 5 BAR Gm9779 0.2085075 6 BAR Apod 0.1959992 But why this failed? library("reshape2"); dat <-read.table("http://dpaste.com/1446132/plain/",header=FALSE) rownames(dat) <- dat[

How to increase sample frequency of dataset (reshape, interpolate?) and fill the Nan values with means

坚强是说给别人听的谎言 提交于 2019-12-31 05:09:33
问题 I have a dataset with an uneven sample frequency as seen on this subset: time date x y id nn1 nn2 0 2019-09-17 08:43:06 234 236 4909 22.02271554554524 38.2099463490856 0 2019-09-17 08:43:06 251 222 4911 22.02271554554524 46.57252408878007 1 2019-09-17 08:43:07 231 244 4909 30.4138126514911 41.617304093369626 1 2019-09-17 08:43:07 252 222 4911 30.4138126514911 46.57252408878007 1 2019-09-17 08:43:07 207 210 4900 41.617304093369626 46.57252408878007 2 2019-09-17 08:43:08 234 250 4909 33

Group values with identical ID into columns without summerizing them in R

两盒软妹~` 提交于 2019-12-31 03:40:44
问题 I have a dataframe that looks like this, but with a lot more Proteins Protein z Irak4 -2.46 Irak4 -0.13 Itk -0.49 Itk 4.22 Itk -0.51 Ras 1.53 For further operations I need the data to be grouped by Proteinname into columns like this. Irak4 Itk Ras -2.46 -0.49 1.53 -0.13 4.22 NA NA -0.51 NA I tried different packages like dplyr or reshape, but did not manage to transform the data into the desired format. Is there any way to achieve this? I think the missing datapoints for some Proteins are the

reshape from base vs dcast from reshape2 with missing values

放肆的年华 提交于 2019-12-31 02:45:32
问题 Whis this data frame, df <- expand.grid(id="01", parameter=c("blood", "saliva"), visit=c("V1", "V2", "V3")) df$value <- c(1:6) df$sex <- rep("f", 6) df > df id parameter visit value sex 1 01 blood V1 1 f 2 01 saliva V1 2 f 3 01 blood V2 3 f 4 01 saliva V2 4 f 5 01 blood V3 5 f 6 01 saliva V3 6 f When I reshape it in the "wide" format, I get identical results with both the base reshape function and the dcast function from reshape2 . reshape(df, timevar="visit", idvar=c("id", "parameter", "sex"

transpose matrix R

两盒软妹~` 提交于 2019-12-30 07:15:26
问题 I have a data frame in R that I want to transpose into a different format, please see the example below: Can I use the transpose function in R? Input data frame: Samples A1 A2 A3 B1 B2 B3 Sample1 123 123 321 32 321 32132 Sample2 12321 32321 2321 2313 3213 3123 Sample3 454 54 543 543 43 435 Desired Output: Samples 1 2 3 Sample1 A 123 123 321 Sample1 B 32 321 32132 Sample2 A 12321 32321 2321 Sample2 B 2313 3213 3123 Sample3 A 454 54 543 Sample3 B 543 43 435 回答1: To give some props to base R,

How does numpy.reshape() with order = 'F' work?

一个人想着一个人 提交于 2019-12-30 03:17:10
问题 I thought I understood the reshape function in Numpy until I was messing around with it and came across this example: a = np.arange(16).reshape((4,4)) which returns: array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) This makes sense to me, but then when I do: a.reshape((2,8), order = 'F') it returns: array([[0, 8, 1, 9, 2, 10, 3, 11], [4, 12, 5, 13, 6, 14, 7, 15]]) I would expect it to return: array([[0, 4, 8, 12, 1, 5, 9, 13], [2, 6, 10, 14, 3, 7, 11, 15]]) Can someone

Reshaping 3D Numpy Array to a 2D array

谁都会走 提交于 2019-12-29 09:12:26
问题 I have the following 3D array in Numpy: a = np.array([[[1,2],[3,4]], [[5,6],[7,8]], [[9,10],[11,12]],[[13,14],[15,16]]]) when I write b = np.reshape(a, [4,4]) The 2D resulting array will look like [[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12] [13 14 15 16]] However, I want it to be in this shape: [[ 1 2 5 6] [ 3 4 7 8] [ 9 10 13 14] [11 12 15 16]] How can I do this efficiently in Python/Numpy? 回答1: Reshape to split the first axis into two, permute axes and one more reshape - a.reshape(2,2,2,2)

Long and wide data – when to use what? [closed]

走远了吗. 提交于 2019-12-29 05:21:25
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I'm in the process of compiling data from different data sets into one data set for analysis. I'll be doing data exploration, trying different things to find out what regularities may be hidden in the data, so I don't currently have a specific method in mind. Now I'm wondering if

load csv into 2D matrix with numpy for plotting

☆樱花仙子☆ 提交于 2019-12-28 03:31:08
问题 Given this CSV file: "A","B","C","D","E","F","timestamp" 611.88243,9089.5601,5133.0,864.07514,1715.37476,765.22777,1.291111964948E12 611.88243,9089.5601,5133.0,864.07514,1715.37476,765.22777,1.291113113366E12 611.88243,9089.5601,5133.0,864.07514,1715.37476,765.22777,1.291120650486E12 I simply want to load it as a matrix/ndarray with 3 rows and 7 columns. However, for some reason, all I can get out of numpy is an ndarray with 3 rows (one per line) and no columns. r = np.genfromtxt(fname