similar to: How to duplicate each row in a data.frame?

Displaying 20 results from an estimated 10000 matches similar to: "How to duplicate each row in a data.frame?"

2010 Jun 28
3
data frame row statistics (mean)?
Hello, I am trying to calculate the mean value of each row in a data frame (d), I am having troubles and getting errors using the code I have written. Below is a brief example of the code, any thought or suggestions would be great. Thank you for your time, Doug # Example Code: d <- data.frame(st1=c(1,2,3,4), st2=c(2,5,6,7), st3=c(5,5,NA,7), st4=c(6,5,7,8)) avg <-
2010 Apr 13
2
efficiently picking one row from a data frame per unique key
Hello all, I'm trying to transform data frames by grouping the rows by the values in a particular column, ordered by another column, then picking the first row in each group. I'd like to convert a data frame like this: x y z 1 10 20 1 11 19 2 12 18 4 13 17 into one with three rows, like this, where i've discarded one row: x y z 1 1 11 19 2 2 12 18 4 4 13 17 I've got a
2011 Feb 17
2
sort by column and row names
Hello, All, How can one sort on column and row names. For example: How can this X1 X3 X2 X1 1 0 0 X3 0 1 0 X2 0 0 1 become this? X1 X2 X3 X1 1 0 0 X2 0 1 0 X3 0 0 1 Thank you for your time! Jim [[alternative HTML version deleted]]
2011 Feb 10
2
Calculating rowMeans from different columns in each row?
Hello! I have a dataset like this: X1 X2 X3 X4 X5 X6 X7 X8 1 2 2 1 2 3 2 6 2 3 2 5 7 9 1 3 1 9 12 6 1 1 3 6 The columns X1-X6 contains ordinary numeric values. X7 contains the number of the first column that the rowMeans should be calculated from and X8 contains the last column
2011 Feb 10
1
highest and second highest value in row for each combination
Dear R-List, I have a dataframe area<-c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5,10)) type<-c(rep(1:10,5)) a<-rnorm(50) b<-rnorm(50) c<-rnorm(50) d<-rnorm(50) df<-cbind(area,type,a,b,c,d) df area type a b c d [1,] 1 1 0.45608192 0.240378547 2.05208079 -1.18827462 [2,] 1 2 -0.12119506 -0.028078577
2010 Feb 03
5
How to export the examples in help(something) to a file?
Some examples in the help page are too long to be copied from screen. Could somebody let me know some easy way on how to extract the example to a file so that I can play with them?
2009 Oct 04
2
Row to Column help
Dear R Community, I am attempting to transpose a dataset from rows to columns but am stuck. I have tried using reshape() with little luck, possibly due to the categorical nature of the data. For example: id<-c(1,2,2,3,3,3) author<-c("j","k","k","l","l","l")
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
2010 Jun 03
4
data-management: Rowwise NA
Dear R´ers.. In this mock dataset how can I generate a logical variable based on whether just tes or tes3 are NA in each row?? test<-sample(c("A",NA,"B"),100,replace=T) test2<-sample(c("A",NA,"B"),100,replace=T) test3<-sample(c("A",NA,"B"),100,replace=T) tes<-cbind(test,test2,test3)
2009 Oct 15
1
performing function on lists where each element is a data frame
I have browsed the archive, and played around with a whole bunch of ways of approaching the problem, and I cannot get the answer that I want. I have a list with 2000 elements. Each element is a data frame with 2 columns. As an example, see element 1999 below. [[1999]] H N 6 0.54 26 10 0.31 13 11 0.12 34 13 0.00 38 4 0.59 37 16 0.44 9 19 0.08 13 14 0.64 39 8
2010 Jan 01
5
How to not to terminate read.table if the input file is empty?
read.table terminates the program if the input file is empty. Is there way to let the program continue and return me a NULL instead of terminating the program? $ Rscript read_empty.R > read.table("empty_data.txt") Error in read.table("empty_data.txt") : no lines available in input Execution halted $ cat read_empty.R read.table("empty_data.txt") $ cat
2011 Jul 24
2
Deleting rows and store the deleted rows in new data frame
Dear all, I am using grep but I did not understand the problem as I am doing something wrong.Please help me. I am using this code- sf=data.frame(sapply(df[],function(x) grep('\\.&\\,', df[,9]))) the thing is i have a data frame(df) like this- 10 135349467 g G 4 0 0 5 ,,,., 10 135349468 t T 2 0 0 5 ,,c., 10 135349469 g G 7 0 0 5 ,,a., 10 135349470 c C 8 0 0 5 ,,,., 10 135349471
2010 Dec 08
1
sd() for numeric row entries
How might one calculate standard deviation, row-wise, for the numeric values in a data frame such as this one V1 V2 V3 V4 V5 1 rs11089130 0.4565 0.4574 0.4569 0.4572 2 rs738829 0.6548 0.6519 0.6448 0.6549 3 rs915674 0.7503 0.7500 0.7517 0.7502 and place the standard deviation in a 6th column called “std_dev”? Regards, Jim [[alternative HTML version deleted]]
2009 Dec 18
4
How to print to file?
I don't find a function to print a string to file. Would somebody let me know what function I should use?
2009 Aug 10
5
Example scripts for R Manual
Hi, I am wondering if some experienced users would help put the ready-to-run code of the examples in the manuals. It would help new users learn R faster by putting all the examples in an ready-to-run R script file. Can somebody help do so sometime and post the code along with the pdf manuals? http://cran.r-project.org/manuals.html Regards, Peng
2010 Nov 29
3
data.frame and formula classes of aggregate
Hi - I apologize for the 2nd post, but I think my question from a few weeks ago may have been overlooked on a Friday afternoon. I might be missing something very obvious, but is it widely known that the aggregate function handles missing values differently depending if a data frame or a formula is the first argument ? For example, (d<- data.frame(sex=rep(0:1,each=3),
2009 Sep 14
3
How to refer to the last a few rows?
Hi, x=matrix(1:60,nr=6) I can refer the last 2 rows by x[5:6,] If I don't know the total number of rows is 6, is there a way to refer the last 2 rows? Regards, Peng
2011 Feb 08
2
delete a row in dataframe w/o changing indexing
Hi All, I'm trying to delete a row from my dataframe "pop" without changing the indexing (column 0) as follows: >pop id birth size xloc yloc weight energy gonad consumed 1 1 36 13 34 43 0 18 0 0 2 2 36 10 39 38 0 18 0 0 3 3 36 10 37 35 0 18 0 0 4 4 36 10 31 25 0
2009 Oct 02
3
How to get duplicated items in a vector?
Hi, > x=c(rep(1,3),rep(3,2)) > x [1] 1 1 1 3 3 > duplicated(x) [1] FALSE TRUE TRUE FALSE TRUE > As shown in the above code, 'duplicated' doesn't return 'F' for the first '1' and first '3' in 'x'. I am wondering if there is a function that can return an indicator for any element whether it appears in a vector twice or more. Regards, Peng
2010 Jan 21
3
Anova unequal variance
I found this paper on ANOVA on unequal error variance. Has this be incorporated to any R package? Is there any textbook that discuss the problem of ANOVA on unequal error variance in general? http://www.jstor.org/stable/2532947?cookieSet=1