[R] Odp: data.frame
Petr PIKAL
petr.pikal at precheza.cz
Mon Jun 18 16:01:24 CEST 2007
Hi
Why scratching your left ear with your right hand?
If M is numeric matrix
d.m <- data.frame(M)
names(d.m) <- paste("Rep", 1:dim(M)[2], sep="")
not sure what you want as row names as var is not defined anywhere in your
code, but you can use the same principle for changing row names. Jus use
row.names(d.m) <- whatever vector of names you can elaborate
Regards
Petr Pikal
petr.pikal at precheza.cz
BTW. R is not C and you shall use strong features of R not to try to avoid
them.
r-help-bounces at stat.math.ethz.ch napsal dne 18.06.2007 15:40:38:
> hello,
> I'm trying to write a function which take a matrix and give a dataframe
with
> column names and row names but the problem I meet it's that the column
number
> is changing and the vector containing the column names is also changing
how
> can I do to write a good progam for the moment I tryied like follow:
>
> dm <- ncol(M)
> v <- vector()
> t <- 1
> while (dm > 0) {
> v <- c(v,paste("Rép",t,sep=""))
> t <- t + 1
> dm <- dm - 1
> }
> nv <- noquote(v)
> df <- function (M,x) {
> return(data.frame(nv[1] = M[,1], nv[2] = M[,2],nv[3] = M[,3], row.names
=
> var[[1]], check.rows = TRUE, check.names = TRUE))
> }
>
> I know that there are errors but the important is that R doesn't
recognize nv.
> For more precision the martix M is like follow:
>
> M
> [,1] [,2] [,3]
> [1,] 6.52 NA 6.59
> [2,] 6.99 6.85 6.38
> [3,] 6.92 6.72 6.99
> [4,] 6.59 5.51 6.45
> [5,] 6.65 7.12 6.99
> [6,] 6.18 5.71 5.78
> [7,] 6.65 6.52 6.72
> [8,] 6.65 6.79 6.12
> [9,] 6.59 6.65 6.32
> [10,] 5.85 6.05 6.38
> [11,] 6.38 6.79 6.65
> [12,] 6.79 6.52 6.72
> [13,] 6.12 6.25 6.38
> [14,] 6.99 6.72 6.38
> [15,] 6.59 6.65 6.99
> [16,] 6.45 6.18 6.59
> [17,] 5.65 6.05 6.52
> [18,] 6.52 6.85 6.65
> [19,] 6.18 6.32 6.32
> [20,] 6.99 6.65 6.72
> [21,] 6.52 6.99 6.32
>
> Can you help me?
> thanks.
>
>
>
_____________________________________________________________________________
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo!
Mail
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list