My mistake.
cars2 should be initalized to have all the extra rows.
cars2 <- data.frame(matrix(rep(NA, prod(dim(cars)) + ncol(cars)),
nrow(cars)+1))
cars2[2:nrow(cars2),] <- cars
In this way, insertion at any row is possible.
Nikhil
On May 17, 2010, at 2:46 PM, Peter Ehlers wrote:
data(
Works with warnings for me. but your method is better.
Nikhil
On May 17, 2010, at 1:35 PM, Peter Ehlers wrote:
data(cars)
cars2 <- cars
cars2[2:nrow(cars)+1,] <- cars2[1:nrow(cars),]
cars2[1,] <- NA
__
R-help@r-project.org mailing list
https://sta
On 2010-05-17 11:14, Nikhil Kaza wrote:
Does this work?
data(cars)
cars2 <- cars
cars2[2:nrow(cars)+1,] <- cars2[1:nrow(cars),]
cars2[1,] <- NA
Not for me. Did you try it?
-Peter Ehlers
Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina
nikhil.l...@gmail
On 2010-05-17 9:28, ecvet...@uwaterloo.ca wrote:
I have a large data frame 48:2185 with different numbers.
I would like to add only one row at the very top of my data frame with
0's or NA's.
I don't know which approach to use. Should i create 2 different data
frames and merge them? Ive also tried
Does this work?
data(cars)
cars2 <- cars
cars2[2:nrow(cars)+1,] <- cars2[1:nrow(cars),]
cars2[1,] <- NA
Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina
nikhil.l...@gmail.com
On May 17, 2010, at 11:28 AM, ecvet...@uwaterloo.ca wrote:
I have a large dat
Try this:
> x <- data.frame(a=1:10, b=1:10)
> x
a b
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
> # add a row at the top
> x <- x[c(1,seq(nrow(x))),]
> x
a b
11 1
1.1 1 1
22 2
33 3
44 4
55 5
66 6
77 7
8
I have a large data frame 48:2185 with different numbers.
I would like to add only one row at the very top of my data frame with
0's or NA's.
I don't know which approach to use. Should i create 2 different data
frames and merge them? Ive also tried the rbind command with no luck.
I would app
7 matches
Mail list logo