I have a list/dataframe such as
a b c d e f g VALUE
1 0 1 0 0 0 1 934
what I wanted to do is to print,
1010001
without using for loop. so basically, take those integers as a string and merge them while printing?
I have a list/dataframe such as
a b c d e f g VALUE
1 0 1 0 0 0 1 934
what I wanted to do is to print,
1010001
without using for loop. so basically, take those integers as a string and merge them while printing?
I will define a function, which truncate the last value and paste all the other elements together. And then use "apply" on all the dataframe
cc <- data.frame(a=1,b=0,c=1,d=0,e=0,f=0,g=1,VALUE=934)
# This function contains the all the jobs you want to do for the row.
myfuns <- function(x, collapse=""){
x <- x[-length(x)] # truncate the last element
paste(x,collapse="") # paste all the integers together
}
# the second argument "MARGIN=1" means apply this function on the row
apply(cc,MARGIN=1,myfuns2) # output: "1010001"