I have this data in R:
column1 = c("A", "B", "C")
column2 = c("AA", "BB", "CC", "DD")
column3 = c("AAA")
na.pad <- function(x,len){
x[1:len]
}
makePaddedDataFrame <- function(l,...){
maxlen <- max(sapply(l,length))
data.frame(lapply(l,na.pad,len=maxlen),...)
}
d = makePaddedDataFrame(list(x=column1,y=column2,z=column3))
x y z
1 A AA AAA
2 B BB <NA>
3 C CC <NA>
4 <NA> DD <NA>
- I would like to give "Ascending ID's" to each element in this table such that NA's are not assigned an ID - for example:
In this above example:
The first row of Column X is assigned as id = 1, the second row of Column X is assigned as id = 2, the third row of Column X is assigned as id = 3, and the fourth row of Column X is skipped because there is an NA
Since there are no NA's in Column Y, the first row of Column Y is assigned as id = 4 (picks off from the previous row), the second row of Column Y is assigned as id = 5, the third row of Column Y is assigned as id = 6, and the fourth row of Column Y is assigned as id = 7
Since all rows in Column Z are NA except the first row, only the first row of Column Z is assigned as id = 8 and all other rows are skipped.
