Re: [R] data.frame

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 18 Jun 2007 10:04:09 -0400

Is this close to what you want? 'var' was not defined for row.names.

> M <- matrix(scan(textConnection(x)), ncol=3, byrow=TRUE)
Read 63 items
> dm <- ncol(M)
> v <- vector()
> t <- 1
> while (dm > 0) {

+  v <- c(v,paste("Rép",t,sep=""))
+  t <- t + 1
+  dm <- dm - 1
+ }

> df <- as.data.frame(M)
> colnames(df) <- v
> df

   Rép1 Rép2 Rép3

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

>

On 6/18/07, elyakhlifi mustapha <elyakhlifi_mustapha_at_yahoo.fr> wrote:
>
> 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.
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[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.

Received on Mon 18 Jun 2007 - 19:36:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Jun 2007 - 20:33:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.