Displaying 4 results from an estimated 4 matches for "mydoit".
Did you mean:
doit
2024 Dec 01
6
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
...e=date)
class(olddata)
cat("This is the original data frame","\n")
print(olddata)
# This function is supposed to identify the first row
# within each level of ID and, for the first row, set
# the variable first to 1, and for all rows other than
# the first row set first to 0.
mydoit <- function(df){
value <- ifelse (first(df[,"ID"]),1,0)
cat("value=",value,"\n")
df[,"first"] <- value
}
newdata <- aggregate(olddata,list(olddata[,"ID"]),mydoit)
Thank you,
John
John David Sorkin M.D., Ph.D.
Professor of Medici...
2024 Dec 01
2
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
...ot;,"\n")
> > print(olddata)
> >
> > # This function is supposed to identify the first row
> > # within each level of ID and, for the first row, set
> > # the variable first to 1, and for all rows other than
> > # the first row set first to 0.
> > mydoit <- function(df){
> > value <- ifelse (first(df[,"ID"]),1,0)
> > cat("value=",value,"\n")
> > df[,"first"] <- value
> > }
> > newdata <- aggregate(olddata,list(olddata[,"ID"]),mydoit)
> >
>...
2024 Dec 02
1
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
...ot;,"\n")
> > print(olddata)
> >
> > # This function is supposed to identify the first row
> > # within each level of ID and, for the first row, set
> > # the variable first to 1, and for all rows other than
> > # the first row set first to 0.
> > mydoit <- function(df){
> > value <- ifelse (first(df[,"ID"]),1,0)
> > cat("value=",value,"\n")
> > df[,"first"] <- value
> > }
> > newdata <- aggregate(olddata,list(olddata[,"ID"]),mydoit)
> >
> >...
2024 Dec 02
0
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
...ot;,"\n")
> > print(olddata)
> >
> > # This function is supposed to identify the first row
> > # within each level of ID and, for the first row, set
> > # the variable first to 1, and for all rows other than
> > # the first row set first to 0.
> > mydoit <- function(df){
> > value <- ifelse (first(df[,"ID"]),1,0)
> > cat("value=",value,"\n")
> > df[,"first"] <- value
> > }
> > newdata <- aggregate(olddata,list(olddata[,"ID"]),mydoit)
> >
>...