On Mar 9, 2012, at 10:41 AM, David Winsemius wrote:


On Mar 9, 2012, at 5:31 AM, RMSOPS wrote:

Hello,

   the idea is to copy the d for df, with new results.

x<-data.frame(name="x1",pos=4,age=20)
x<-rbind(x,data.frame(name="x2",pos=5,age=20))
x<-rbind(x,data.frame(name="x3",pos=6,age=21))
x<-rbind(x,data.frame(name="x4",pos=7,age=24))
x<-rbind(x,data.frame(name="x5",pos=8,age=27))
x<-rbind(x,data.frame(name="x6",pos=9,age=26))

x <- data.frame(name=paste("x", 1:6, sep=""),
               pos=3+1:6,
               age=c(20,20, 21,24,27,26))

Added the missing comma and paren:

Is this what you were attempting?

> df <- x
> df$pos[2:nrow(df)] <- df$pos[2:nrow(df)]-4
> names(df) <- c("val_user", "pos", "age")
> df
  val_user pos age
1       x1   4  20
2       x2   1  20
3       x3   2  21
4       x4   3  24
5       x5   4  27
6       x6   5  26



View(x)


d<-NULL
df<-NULL

for(r in 2: nrow(x))
{
val_user<-x$name[[r]]
pos<-x$pos[[r]] -4
age <-x$age[[r]]
d<-data.frame(val_user,pos,age)
print(d)
}
df<-rbind(df,d)
View(df)


It is generally better to spend more time describing the problem. Attempting to read the mind of new R users who come from other programming paradigms is often unrewarding.

--
David.

 in df only have the last result, the ideia is have the new results
calculated in the for loop

thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Copy-dataframe-for-another-tp4456893p4459068.html
Sent from the R help mailing list archive at Nabble.com.

PLEASE: Include context. We are NOT reading this on Nabble.

--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to