r - How to get only numbers from the row? -


i'd ask if there efficient way values row instead of writing:

as.numeric(data[2,]  

example:

data <- data.frame(names=c('train','car', 'plane', 'bicycle'),                    day1 = c(15,22,36,22),                    day2 = c(33,57,2,41),                    day3 = c(87,32,15,25),                    day4 = c(14,2,6,33),                    day5 = c(41,76,11,44),                    day6 = c(11,12,35,25),                    day7 = c(52,2,42,55)) 

not correct:

> data[2,]   names day1 day2 day3 day4 day5 day6 day7 2   car   22   57   32    2   76   12    2 

correct output:

> as.numeric(data[2,]) [1]  2 22 57 32  2 76 12  2 

any "nicer" way such output ?

i think should convert data.frame matrix:

mat <- as.matrix(data[, -1]) rownames(mat) <- data[, 1] mat[2,] 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -