r - Counting the total number of variable without NA -


i have dataframe format of data this:

title,stock1,stock2,stock3 title 1,10,na,na title 2,5,2,3 title3,3,30,na 

i take total number of variables have number. result should this:

title,total_number title 1,1 title 2,4 title3,2 

we can check 'na' values column 2 last column of dataset (!is.na(df1[,-1])) , use rowsums of logical matrix 'total_number'

data.frame(title=df1$title , total_number =rowsums(!is.na(df1[,-1]))) 

Comments