That works great, and is ever so much simpler. Thanks much!
--
View this message in context:
http://r.789695.n4.nabble.com/sapply-lapply-instead-of-loop-tp2320265p2320317.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-projec
So try:
format(as.matrix(temp))
On Tue, Aug 10, 2010 at 4:13 PM, GL wrote:
>
> Both of those approaches seem to return (" v75") instead of ("v75 ").
> --
> View this message in context:
> http://r.789695.n4.nabble.com/sapply-lapply-instead-of-loop-tp2320265p2320305.html
> Sent from the R help
Both of those approaches seem to return (" v75") instead of ("v75 ").
--
View this message in context:
http://r.789695.n4.nabble.com/sapply-lapply-instead-of-loop-tp2320265p2320305.html
Sent from the R help mailing list archive at Nabble.com.
__
R-
Try this:
formatC(as.matrix(temp))
On Tue, Aug 10, 2010 at 3:55 PM, GL wrote:
>
> Using the input below, can I do something more elegant (and more efficient)
> than the loop also listed below to pad strings to a width of 5? The true
> matrix is about 300K rows and 31 columns.
>
> #
will this do what you want:
> newTemp[] <- lapply(newTemp, function(.col){
+ # convert to character and pad to 5 space
+ sprintf("%5s", as.character(.col))
+ })
>
> str(newTemp)
'data.frame': 5 obs. of 3 variables:
$ DX1: chr "13761" "63371" "51745" "64081" ...
$ DX2: chr " 8125" "
Using the input below, can I do something more elegant (and more efficient)
than the loop also listed below to pad strings to a width of 5? The true
matrix is about 300K rows and 31 columns.
###
#INPUT
###
> temp
DX1 DX2 DX3
1 13761 8125 49178
2 6
6 matches
Mail list logo