[R] data.frame loses name when constructed with one column
Not sure why the data.frame function does not capture the name of the column field when its being built with only one column. Can anyone help? data out pred1 predd2 1 1 2.03.0 2 2 3.55.5 3 3 5.5 11.0 data1=data.frame(data[,1]) data1 data...1. 1 1 2 2 3 3 data1=data.frame(data[,1:2]) data1 out pred1 1 1 2.0 2 2 3.5 3 3 5.5 sessionInfo() R version 2.5.1 (2007-06-27) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base [[alternative HTML version deleted]] __ R-help@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.
Re: [R] data.frame loses name when constructed with one column
Try drop=FALSE: x out pred1 predd2 1 1 2.03.0 2 2 3.55.5 3 3 5.5 11.0 x[,1] [1] 1 2 3 data.frame(x[,1]) x...1. 1 1 2 2 3 3 data.frame(x[,1, drop=FALSE]) out 1 1 2 2 3 3 On 9/4/07, Stan Hopkins [EMAIL PROTECTED] wrote: Not sure why the data.frame function does not capture the name of the column field when its being built with only one column. Can anyone help? data out pred1 predd2 1 1 2.03.0 2 2 3.55.5 3 3 5.5 11.0 data1=data.frame(data[,1]) data1 data...1. 1 1 2 2 3 3 data1=data.frame(data[,1:2]) data1 out pred1 1 1 2.0 2 2 3.5 3 3 5.5 sessionInfo() R version 2.5.1 (2007-06-27) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base [[alternative HTML version deleted]] __ R-help@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? __ R-help@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.
[R] data.frame
hello, are there functions giving the columns number and the rows number of a matrix? thanks. _ [[alternative HTML version deleted]] __ R-help@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.
Re: [R] data.frame
See help(dim) and please read the manuals before asking basic questions like this. Thank you. elyakhlifi mustapha wrote: hello, are there functions giving the columns number and the rows number of a matrix? thanks. _ [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] data.frame
On 6/18/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote: hello, are there functions giving the columns number and the rows number of a matrix? Yes, there are. Are you trying to use R without reading *any* documentation??? The mailing list is not a substitute for the manuals. See the Posting guide. Christophe thanks. _ [[alternative HTML version deleted]] __ R-help@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. -- Christophe Pallier (http://www.pallier.org) [[alternative HTML version deleted]] __ R-help@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.
Re: [R] data.frame
On 18 Jun 2007, at 14:16, Adaikalavan Ramasamy wrote: See help(dim) and please read the manuals before asking basic questions like this. Thank you. I think the questioner was looking for row() and col(), which (IMO) are difficult to find if you don't know of their existence. [as indeed are slice.index() or arow() for the array case] Robin elyakhlifi mustapha wrote: hello, are there functions giving the columns number and the rows number of a matrix? thanks. _ [[alternative HTML version deleted]] __ R-help@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. __ R-help@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. -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-help@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.
[R] data.frame
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@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.
Re: [R] data.frame
On 6/18/07, Robin Hankin [EMAIL PROTECTED] wrote: I think the questioner was looking for row() and col(), which (IMO) are difficult to find if you don't know of their existence. Searching for R matrix number of rows columns in google returns, in fourth position, the manual page for 'nrow'. -- Christophe Pallier (http://www.pallier.org) [[alternative HTML version deleted]] __ R-help@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.
Re: [R] data.frame
If M is the original matrix, k - as.data.frame(M) names(k) - paste(Rép,1:ncol(k),sep=) rownames(k) - paste(Col,1:nrow(k),sep=) # replace by what you want k On 6/18/07, elyakhlifi mustapha [EMAIL PROTECTED] 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@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. -- Christophe Pallier (http://www.pallier.org) [[alternative HTML version deleted]] __ R-help@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.
Re: [R] data.frame
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 [EMAIL PROTECTED] 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@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@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.
Re: [R] data.frame and subsetting problem
Yes, the problem I have is finding away to get rid of the extra levels I do not need in the subset. What Don posted works for my needs. I will also read up on factors/levels. Thanks for all suggestions and sorry my example had and error (x2 was supposed to y). Michelle On 6/16/07, Don MacQueen [EMAIL PROTECTED] wrote: I too have no idea what the object named x2 is, or where it came from. Particularly since after your use of subset(), the new dataframe, y, *does* include a row where V2 = 'color'. But I have a guess at what your problem may be. In your original dataframe (x) the first and second columns are factors, because that is the default behavior of read.delim(). Factors have levels. The second column has 5 levels. Try levels(x$V2) to see. When you use subset(), you get fewer rows, but the fact that there were five levels is retained. Then, the plot function sees that that there are five levels, and includes an empty place-holder for the level(s) with no data. Try something like y - data.frame(subset(x, V1 == shirt)) y$V2 - factor(unique(format(y$V2))) to force it to get rid of the now-empty factor levels. There are other ways to do this, I just don't happen to remember any of them at the moment. If I'm right this is a question that comes up fairly often. Might even be in the FAQs. -Don At 12:15 PM -0700 6/16/07, Michelle Wynn wrote: I have read the R online help and wiki and I cannot seem to get something to work the way I need it to. I want to create a new data frame from an subset of an existing data frame which has no reference to the original superset. If you following this example, what I am trying to do may make more sense. I have a file with values like this: shirt,size,40 shirt,color,10 shirt,length,10 shirt,brand, 1 shoes,style,5 shoes,brand,4 shoes,color,1 and I read it into a dataframe like: x - data.frame(read.delim(temp2.txt, sep=,, header=FALSE)) I then want to plot just a subset of this data (say shirts only)... y - data.frame(subset(x, V1 == shirt)) plot(x2[,2:3]) when I do, the resulting plot contains an empty value for 'color' even though my subset has no value in column V2 that equals 'color' anymore. Is it possible create a new data.frame that truly deletes the rows from the original data frame that I am excluding with the subset parameter? Thanks, Michelle [[alternative HTML version deleted]] __ R-help@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. -- - Don MacQueen Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 [EMAIL PROTECTED] - [[alternative HTML version deleted]] __ R-help@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.
[R] data.frame and subsetting problem
I have read the R online help and wiki and I cannot seem to get something to work the way I need it to. I want to create a new data frame from an subset of an existing data frame which has no reference to the original superset. If you following this example, what I am trying to do may make more sense. I have a file with values like this: shirt,size,40 shirt,color,10 shirt,length,10 shirt,brand, 1 shoes,style,5 shoes,brand,4 shoes,color,1 and I read it into a dataframe like: x - data.frame(read.delim(temp2.txt, sep=,, header=FALSE)) I then want to plot just a subset of this data (say shirts only)... y - data.frame(subset(x, V1 == shirt)) plot(x2[,2:3]) when I do, the resulting plot contains an empty value for 'color' even though my subset has no value in column V2 that equals 'color' anymore. Is it possible create a new data.frame that truly deletes the rows from the original data frame that I am excluding with the subset parameter? Thanks, Michelle [[alternative HTML version deleted]] __ R-help@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.
Re: [R] data.frame and subsetting problem
Not sure what 'x2' is that you are plotting; it is not defined. read.delimand subset return dataframes, so you don't need data.frame. Here is something that does work: x - shirt,size,40 + shirt,color,10 + shirt,length,10 + shirt,brand, 1 + shoes,style,5 + shoes,brand,4 + shoes,color,1 x - read.csv(textConnection(x), header=FALSE) x V1 V2 V3 1 shirt size 40 2 shirt color 10 3 shirt length 10 4 shirt brand 1 5 shoes style 5 6 shoes brand 4 7 shoes color 1 plot(subset(x, V1==shirt)[,2:3]) On 6/16/07, Michelle Wynn [EMAIL PROTECTED] wrote: I have read the R online help and wiki and I cannot seem to get something to work the way I need it to. I want to create a new data frame from an subset of an existing data frame which has no reference to the original superset. If you following this example, what I am trying to do may make more sense. I have a file with values like this: shirt,size,40 shirt,color,10 shirt,length,10 shirt,brand, 1 shoes,style,5 shoes,brand,4 shoes,color,1 and I read it into a dataframe like: x - data.frame(read.delim(temp2.txt, sep=,, header=FALSE)) I then want to plot just a subset of this data (say shirts only)... y - data.frame(subset(x, V1 == shirt)) plot(x2[,2:3]) when I do, the resulting plot contains an empty value for 'color' even though my subset has no value in column V2 that equals 'color' anymore. Is it possible create a new data.frame that truly deletes the rows from the original data frame that I am excluding with the subset parameter? Thanks, Michelle [[alternative HTML version deleted]] __ R-help@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@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.
Re: [R] data.frame and subsetting problem
I too have no idea what the object named x2 is, or where it came from. Particularly since after your use of subset(), the new dataframe, y, *does* include a row where V2 = 'color'. But I have a guess at what your problem may be. In your original dataframe (x) the first and second columns are factors, because that is the default behavior of read.delim(). Factors have levels. The second column has 5 levels. Try levels(x$V2) to see. When you use subset(), you get fewer rows, but the fact that there were five levels is retained. Then, the plot function sees that that there are five levels, and includes an empty place-holder for the level(s) with no data. Try something like y - data.frame(subset(x, V1 == shirt)) y$V2 - factor(unique(format(y$V2))) to force it to get rid of the now-empty factor levels. There are other ways to do this, I just don't happen to remember any of them at the moment. If I'm right this is a question that comes up fairly often. Might even be in the FAQs. -Don At 12:15 PM -0700 6/16/07, Michelle Wynn wrote: I have read the R online help and wiki and I cannot seem to get something to work the way I need it to. I want to create a new data frame from an subset of an existing data frame which has no reference to the original superset. If you following this example, what I am trying to do may make more sense. I have a file with values like this: shirt,size,40 shirt,color,10 shirt,length,10 shirt,brand, 1 shoes,style,5 shoes,brand,4 shoes,color,1 and I read it into a dataframe like: x - data.frame(read.delim(temp2.txt, sep=,, header=FALSE)) I then want to plot just a subset of this data (say shirts only)... y - data.frame(subset(x, V1 == shirt)) plot(x2[,2:3]) when I do, the resulting plot contains an empty value for 'color' even though my subset has no value in column V2 that equals 'color' anymore. Is it possible create a new data.frame that truly deletes the rows from the original data frame that I am excluding with the subset parameter? Thanks, Michelle [[alternative HTML version deleted]] __ R-help@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. -- - Don MacQueen Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 [EMAIL PROTECTED] __ R-help@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.
[R] data.frame handling
Dear R-users, I have a little problem that I can't solve by myself. I have a data frame with 2 factors and 8 observations (see the following code): y - c(1,1,1,2,2,3,3,3) y - factor(y) levels(y) - c(a,b,c) x - c(1,2,3,1,2,1,2,3) x - factor(x) levels(x) - c(x,y,z) X - data.frame(factor1=x,factor2=y) and the final result is factor1 factor2 1 x a 2 y a 3 z a 4 x b 5 y b 6 x c 7 y c 8 z c From the above data I'd like to obtain the following matrix: a b c x 1 1 1 y 1 1 1 z 1 0 1 Do you have any advice? Can you help me please? Thank you in advance, Michela __ R-help@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.
Re: [R] data.frame handling
'table()' can compute your desired result in this particular case (though I don't know if it's what you want in general): y - factor(c(a,b,c)[c(1,1,1,2,2,3,3,3)]) x - factor(c(x,y,z)[c(1,2,3,1,2,1,2,3)]) table(x, y) y x a b c x 1 1 1 y 1 1 1 z 1 0 1 If x and y are already columns in a data frame, then just do table(X$factor1, X$factor2) hope this helps, Tony Plate Michela Cameletti wrote: Dear R-users, I have a little problem that I can't solve by myself. I have a data frame with 2 factors and 8 observations (see the following code): y - c(1,1,1,2,2,3,3,3) y - factor(y) levels(y) - c(a,b,c) x - c(1,2,3,1,2,1,2,3) x - factor(x) levels(x) - c(x,y,z) X - data.frame(factor1=x,factor2=y) and the final result is factor1 factor2 1 x a 2 y a 3 z a 4 x b 5 y b 6 x c 7 y c 8 z c From the above data I'd like to obtain the following matrix: a b c x 1 1 1 y 1 1 1 z 1 0 1 Do you have any advice? Can you help me please? Thank you in advance, Michela __ R-help@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. __ R-help@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.
Re: [R] Data.frame columns in R console
Thank you for your answer. When I set options(width=250) I still get the same result when I print the data.frame on my Rgui console (R 2.4.1, Windows XP). Colums become underneath each other. I also get an error (?) message [ reached getOption(max.print) -- omitted 3462 rows ]]. For example if I have a data.frame with 4000 rows and 200 columns I would like to be able to use scroll bars in Rconsole to investigate the whole data.frame. btw, R is very useful system, my sincere thanks goes to R developers! -Lauri 2007/2/8, Prof Brian Ripley [EMAIL PROTECTED]: ?options, look for 'width'. I don't know what OS this in: the Windows Rgui has an option to set the width to the width of the console, but you can override it. On Thu, 8 Feb 2007, Lauri Nikkinen wrote: Hi R-users, A newbie question: assume that I have for example 30 columns in my data.frame named DF. When I print DF in R console I get columns that don't fit on the same row underneath each other. So how do I change the R console preferences so that the console does not wrap my data.frame columns? I want the columns to be printed next to each other, as in a normal table. Cheers, Lauri [[alternative HTML version deleted]] __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Data.frame columns in R console
On Fri, 9 Feb 2007, Lauri Nikkinen wrote: Thank you for your answer. When I set options(width=250) I still get the same result when I print the data.frame on my Rgui console (R 2.4.1, Windows XP). Colums become underneath each other. I also get an error (?) message [ reached getOption(max.print) -- omitted 3462 rows ]]. For example if I have a data.frame with 4000 rows and 200 columns I would like to be able to use scroll bars in Rconsole to investigate the whole data.frame. 200 columns will take far more than 250 characters. The help says 'width': controls the number of characters on a line. You may want to change this if you re-size the window that R is running in. Valid values are 10...1 with default normally 80. I would use the spreadsheet view of edit(mydf) in preference. btw, R is very useful system, my sincere thanks goes to R developers! -Lauri 2007/2/8, Prof Brian Ripley [EMAIL PROTECTED]: ?options, look for 'width'. I don't know what OS this in: the Windows Rgui has an option to set the width to the width of the console, but you can override it. On Thu, 8 Feb 2007, Lauri Nikkinen wrote: Hi R-users, A newbie question: assume that I have for example 30 columns in my data.frame named DF. When I print DF in R console I get columns that don't fit on the same row underneath each other. So how do I change the R console preferences so that the console does not wrap my data.frame columns? I want the columns to be printed next to each other, as in a normal table. Cheers, Lauri [[alternative HTML version deleted]] __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[alternative HTML version deleted]] __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] Data.frame columns in R console
Hi On 9 Feb 2007 at 10:17, Lauri Nikkinen wrote: Date sent: Fri, 9 Feb 2007 10:17:48 +0200 From: Lauri Nikkinen [EMAIL PROTECTED] To: Prof Brian Ripley [EMAIL PROTECTED] Copies to: r-help@stat.math.ethz.ch Subject:Re: [R] Data.frame columns in R console Thank you for your answer. When I set options(width=250) I still get the same result when I print the data.frame on my Rgui console (R 2.4.1, Windows XP). Colums become underneath each other. I also get an error (?) message [ reached getOption(max.print) -- omitted 3462 rows ]]. For example if I have a data.frame with 4000 rows and 200 columns I would like to be able to use scroll bars in Rconsole to investigate the whole data.frame. I am not sure if it is the best idea. You shall probably use other means for checking your data frame. Try ?summary, ?str or if you really want to check all values in data frame you can use invisible(edit(test)) to open a spreadsheet like editor. HTH Petr btw, R is very useful system, my sincere thanks goes to R developers! -Lauri 2007/2/8, Prof Brian Ripley [EMAIL PROTECTED]: ?options, look for 'width'. I don't know what OS this in: the Windows Rgui has an option to set the width to the width of the console, but you can override it. On Thu, 8 Feb 2007, Lauri Nikkinen wrote: Hi R-users, A newbie question: assume that I have for example 30 columns in my data.frame named DF. When I print DF in R console I get columns that don't fit on the same row underneath each other. So how do I change the R console preferences so that the console does not wrap my data.frame columns? I want the columns to be printed next to each other, as in a normal table. Cheers, Lauri [[alternative HTML version deleted]] __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[alternative HTML version deleted]] __ R-help@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. Petr Pikal [EMAIL PROTECTED] __ R-help@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.
Re: [R] Data.frame columns in R console
Ok. Thanks for all of you. I have used fix, edit, summary and str for checking my data. Before R I have used SAS and SPSS so I'm used to view my data in spreadsheet. -Lauri 2007/2/9, Petr Pikal [EMAIL PROTECTED]: Hi On 9 Feb 2007 at 10:17, Lauri Nikkinen wrote: Date sent: Fri, 9 Feb 2007 10:17:48 +0200 From: Lauri Nikkinen [EMAIL PROTECTED] To: Prof Brian Ripley [EMAIL PROTECTED] Copies to: r-help@stat.math.ethz.ch Subject:Re: [R] Data.frame columns in R console Thank you for your answer. When I set options(width=250) I still get the same result when I print the data.frame on my Rgui console (R 2.4.1, Windows XP). Colums become underneath each other. I also get an error (?) message [ reached getOption(max.print) -- omitted 3462 rows ]]. For example if I have a data.frame with 4000 rows and 200 columns I would like to be able to use scroll bars in Rconsole to investigate the whole data.frame. I am not sure if it is the best idea. You shall probably use other means for checking your data frame. Try ?summary, ?str or if you really want to check all values in data frame you can use invisible(edit(test)) to open a spreadsheet like editor. HTH Petr btw, R is very useful system, my sincere thanks goes to R developers! -Lauri 2007/2/8, Prof Brian Ripley [EMAIL PROTECTED]: ?options, look for 'width'. I don't know what OS this in: the Windows Rgui has an option to set the width to the width of the console, but you can override it. On Thu, 8 Feb 2007, Lauri Nikkinen wrote: Hi R-users, A newbie question: assume that I have for example 30 columns in my data.frame named DF. When I print DF in R console I get columns that don't fit on the same row underneath each other. So how do I change the R console preferences so that the console does not wrap my data.frame columns? I want the columns to be printed next to each other, as in a normal table. Cheers, Lauri [[alternative HTML version deleted]] __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[alternative HTML version deleted]] __ R-help@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. Petr Pikal [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Data.frame columns in R console
Petr == Petr Pikal [EMAIL PROTECTED] on Fri, 09 Feb 2007 09:42:13 +0100 writes: Petr Hi Petr On 9 Feb 2007 at 10:17, Lauri Nikkinen wrote: Thank you for your answer. When I set options(width=250) I still get the same result when I print the data.frame on my Rgui console (R 2.4.1, Windows XP). Colums become underneath each other. I also get an error (?) message [ reached getOption(max.print) -- omitted 3462 rows ]]. As Petr explains below (and Brian Ripley), you *really* should use different means here --- but I think this is the first time that the relatively new option 'max.print' has hit R-help, hence one other hint, maybe useful to the public: Note that the 'max.print' option was introduced exactly for the purpose of **protecting** the inadvertent user from a flood of output spilling into his console/gui/.. (and apparently locking up R completely, we have even seen crashes when people wanted to print dataframes/matrices/arrays with millions of entries). So, given the above message (yes, not an error), why did you not try to read help(getOption) and look for the word 'max.print' there ? -- if you really really don't want to follow the advice of Brian and Petr, then say something like options(max.print = 1e6) Martin Maechler, ETH Zurich For example if I have a data.frame with 4000 rows and 200 columns I would like to be able to use scroll bars in Rconsole to investigate the whole data.frame. Petr I am not sure if it is the best idea. You shall probably use other Petr means for checking your data frame. Petr Try ?summary, ?str or if you really want to check all values in data Petr frame you can use Petr invisible(edit(test)) Petr to open a spreadsheet like editor. Petr HTH Petr Petr __ R-help@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.
Re: [R] Data.frame columns in R console
Hi, This still does not solve the issue that when I print in R console I get columns that don't fit in the window underneath each other. Thanks anyway! -Lauri 2007/2/9, Martin Maechler [EMAIL PROTECTED]: Petr == Petr Pikal [EMAIL PROTECTED] on Fri, 09 Feb 2007 09:42:13 +0100 writes: Petr Hi Petr On 9 Feb 2007 at 10:17, Lauri Nikkinen wrote: Thank you for your answer. When I set options(width=250) I still get the same result when I print the data.frame on my Rgui console (R 2.4.1, Windows XP). Colums become underneath each other. I also get an error (?) message [ reached getOption(max.print) -- omitted 3462 rows ]]. As Petr explains below (and Brian Ripley), you *really* should use different means here --- but I think this is the first time that the relatively new option 'max.print' has hit R-help, hence one other hint, maybe useful to the public: Note that the 'max.print' option was introduced exactly for the purpose of **protecting** the inadvertent user from a flood of output spilling into his console/gui/.. (and apparently locking up R completely, we have even seen crashes when people wanted to print dataframes/matrices/arrays with millions of entries). So, given the above message (yes, not an error), why did you not try to read help(getOption) and look for the word 'max.print' there ? -- if you really really don't want to follow the advice of Brian and Petr, then say something like options(max.print = 1e6) Martin Maechler, ETH Zurich For example if I have a data.frame with 4000 rows and 200 columns I would like to be able to use scroll bars in Rconsole to investigate the whole data.frame. Petr I am not sure if it is the best idea. You shall probably use other Petr means for checking your data frame. Petr Try ?summary, ?str or if you really want to check all values in data Petr frame you can use Petr invisible(edit(test)) Petr to open a spreadsheet like editor. Petr HTH Petr Petr [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Data.frame columns in R console
Lauri == Lauri Nikkinen [EMAIL PROTECTED] on Fri, 9 Feb 2007 14:21:26 +0200 writes: Lauri This still does not solve the issue that when I print in R console I get Lauri columns that don't fit in the window underneath each other. Thanks anyway! But Brian did give you all you needed (even more I'd say) to solve that !?!? Please apologize if I use a bit frank language, but using R, you *really* are expected to read the documentation which is written pretty carefully {probably that's what some people don't like about it and call confusing ??}. Specifically, Brian said BDR 200 columns will take far more than 250 characters. The help says and then pointed you to the docu for options(width = .). I think you need to reread that paragraph, particularly the word 'character' and then you will understand that your original approach of using options(width = 250) can *not* be what you want if your dataframe has 200 columns. Martin Lauri 2007/2/9, Martin Maechler [EMAIL PROTECTED]: Petr == Petr Pikal [EMAIL PROTECTED] on Fri, 09 Feb 2007 09:42:13 +0100 writes: Petr Hi Petr On 9 Feb 2007 at 10:17, Lauri Nikkinen wrote: Thank you for your answer. When I set options(width=250) I still get the same result when I print the data.frame on my Rgui console (R 2.4.1, Windows XP). Colums become underneath each other. I also get an error (?) message [ reached getOption(max.print) -- omitted 3462 rows ]]. As Petr explains below (and Brian Ripley), you *really* should use different means here --- but I think this is the first time that the relatively new option 'max.print' has hit R-help, hence one other hint, maybe useful to the public: Note that the 'max.print' option was introduced exactly for the purpose of **protecting** the inadvertent user from a flood of output spilling into his console/gui/.. (and apparently locking up R completely, we have even seen crashes when people wanted to print dataframes/matrices/arrays with millions of entries). So, given the above message (yes, not an error), why did you not try to read help(getOption) and look for the word 'max.print' there ? -- if you really really don't want to follow the advice of Brian and Petr, then say something like options(max.print = 1e6) Martin Maechler, ETH Zurich For example if I have a data.frame with 4000 rows and 200 columns I would like to be able to use scroll bars in Rconsole to investigate the whole data.frame. Petr I am not sure if it is the best idea. You shall probably use other Petr means for checking your data frame. Petr Try ?summary, ?str or if you really want to check all values in data Petr frame you can use Petr invisible(edit(test)) Petr to open a spreadsheet like editor. Petr HTH Petr Petr Lauri [[alternative HTML version deleted]] Lauri __ Lauri R-help@stat.math.ethz.ch mailing list Lauri https://stat.ethz.ch/mailman/listinfo/r-help Lauri PLEASE do read the posting guide http://www.R-project.org/posting-guide.html Lauri and provide commented, minimal, self-contained, reproducible code. __ R-help@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.
[R] Data.frame columns in R console
Hi R-users, A newbie question: assume that I have for example 30 columns in my data.frame named DF. When I print DF in R console I get columns that don't fit on the same row underneath each other. So how do I change the R console preferences so that the console does not wrap my data.frame columns? I want the columns to be printed next to each other, as in a normal table. Cheers, Lauri [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Data.frame columns in R console
?options, look for 'width'. I don't know what OS this in: the Windows Rgui has an option to set the width to the width of the console, but you can override it. On Thu, 8 Feb 2007, Lauri Nikkinen wrote: Hi R-users, A newbie question: assume that I have for example 30 columns in my data.frame named DF. When I print DF in R console I get columns that don't fit on the same row underneath each other. So how do I change the R console preferences so that the console does not wrap my data.frame columns? I want the columns to be printed next to each other, as in a normal table. Cheers, Lauri [[alternative HTML version deleted]] __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.
[R] data.frame to shape
Hi all, I have a simple question: I have a data.frame like this: id x y 1 50 1647685 4815259 2 50 1647546 4815196 3 50 1647454 4815294 4 50 1647405 4815347 5 50 1647292 4815552 6 50 1647737 4815410 7 74 1647555 4815201 8 74 1647464 4815023 9 74 1646970 4815129 10 74 1646895 4815264 11 74 1646762 4815513 and I'd like to trasform it with the convert.to.shapefile function (shapefiles package) but to make this I must have a data.frame like this: id x y 1 50 1647685 4815259 2 50 1647546 4815196 3 50 1647454 4815294 4 50 1647405 4815347 5 50 1647292 4815552 6 50 1647737 4815410 7 50 1647685 4815259 8 74 1647555 4815201 9 74 1647464 4815023 10 74 1646970 4815129 11 74 1646895 4815264 12 74 1646762 4815513 13 74 1646762 4815513 with the first point of every id repeated to close the polygon. There is a function to make this indipendently by the number of the id Best regards Leonardo -- Leonardo Lami email + jabber: [EMAIL PROTECTED] www.faunalia.it Cell: (+39)349-1310164 Tel+Fax: (+39) 0587-213742 Piazza Garibaldi 5 - 56025 Pontedera (PI), Italy __ R-help@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.
[R] R: data.frame to shape
assuming that the rows are sorted correctly dat id x y 1 50 1647685 4815259 2 50 1647546 4815196 3 50 1647454 4815294 4 50 1647405 4815347 5 50 1647292 4815552 6 50 1647737 4815410 7 74 1647555 4815201 8 74 1647464 4815023 9 74 1646970 4815129 10 74 1646895 4815264 11 74 1646762 4815513 list.dat-split(dat, dat$id) closed.polygons-lapply(list.dat, function(x) rbind(x, x[1,])) do.call(rbind, closed.polygons) id x y 50.1 50 1647685 4815259 50.2 50 1647546 4815196 50.3 50 1647454 4815294 50.4 50 1647405 4815347 50.5 50 1647292 4815552 50.6 50 1647737 4815410 50.11 50 1647685 4815259 74.7 74 1647555 4815201 74.8 74 1647464 4815023 74.9 74 1646970 4815129 74.10 74 1646895 4815264 74.11 74 1646762 4815513 74.71 74 1647555 4815201 but maybe there are better ways to do what you want -Messaggio originale- Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] conto di Leonardo Lami Inviato: 09 August, 2006 15:33 A: r-help@stat.math.ethz.ch Oggetto: [R] data.frame to shape Hi all, I have a simple question: I have a data.frame like this: id x y 1 50 1647685 4815259 2 50 1647546 4815196 3 50 1647454 4815294 4 50 1647405 4815347 5 50 1647292 4815552 6 50 1647737 4815410 7 74 1647555 4815201 8 74 1647464 4815023 9 74 1646970 4815129 10 74 1646895 4815264 11 74 1646762 4815513 and I'd like to trasform it with the convert.to.shapefile function (shapefiles package) but to make this I must have a data.frame like this: id x y 1 50 1647685 4815259 2 50 1647546 4815196 3 50 1647454 4815294 4 50 1647405 4815347 5 50 1647292 4815552 6 50 1647737 4815410 7 50 1647685 4815259 8 74 1647555 4815201 9 74 1647464 4815023 10 74 1646970 4815129 11 74 1646895 4815264 12 74 1646762 4815513 13 74 1646762 4815513 with the first point of every id repeated to close the polygon. There is a function to make this indipendently by the number of the id Best regards Leonardo -- Leonardo Lami email + jabber: [EMAIL PROTECTED] www.faunalia.it Cell: (+39)349-1310164 Tel+Fax: (+39) 0587-213742 Piazza Garibaldi 5 - 56025 Pontedera (PI), Italy __ R-help@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. __ R-help@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.
Re: [R] data.frame to shape
Try this: DF[unlist(tapply(rownames(DF), DF$id, function(x) c(x, x[1]))),] On 8/9/06, Leonardo Lami [EMAIL PROTECTED] wrote: Hi all, I have a simple question: I have a data.frame like this: id x y 1 50 1647685 4815259 2 50 1647546 4815196 3 50 1647454 4815294 4 50 1647405 4815347 5 50 1647292 4815552 6 50 1647737 4815410 7 74 1647555 4815201 8 74 1647464 4815023 9 74 1646970 4815129 10 74 1646895 4815264 11 74 1646762 4815513 and I'd like to trasform it with the convert.to.shapefile function (shapefiles package) but to make this I must have a data.frame like this: id x y 1 50 1647685 4815259 2 50 1647546 4815196 3 50 1647454 4815294 4 50 1647405 4815347 5 50 1647292 4815552 6 50 1647737 4815410 7 50 1647685 4815259 8 74 1647555 4815201 9 74 1647464 4815023 10 74 1646970 4815129 11 74 1646895 4815264 12 74 1646762 4815513 13 74 1646762 4815513 with the first point of every id repeated to close the polygon. There is a function to make this indipendently by the number of the id Best regards Leonardo -- Leonardo Lami email + jabber: [EMAIL PROTECTED] www.faunalia.it Cell: (+39)349-1310164 Tel+Fax: (+39) 0587-213742 Piazza Garibaldi 5 - 56025 Pontedera (PI), Italy __ R-help@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. __ R-help@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.
[R] data.frame error using sem package
Hi there, I just saw your question on the help list and tough you could help me with some start-up info I just downloaded the R project software to try running SEM analysis and I also downloaded the SEM package. But it just sits there on the desktop and R does not know where it is...I can¹t figure out how to organize the files...When I type ?sem in R it says object sem not found...I can¹t seem to find help on the web on how to set-up the packages Well, thanks in advance __ Patrick Bedard Ph.D. Dept. of Neuroscience Brown University [[alternative HTML version deleted]] __ R-help@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
[R] data.frame
Dear all, Does any one knows why should I get the following error message, when trying to do a simple data.frame?? DataF-data.frame(Subject,BiomR,Spp,Capas,Litter,Herbs,LitterD,MaxCanH,DDifS p,DSSp,Slope, CanDens,NearestSp) Erro em data.frame(Subject, BiomR, Spp, Capas, Litter, Herbs, LitterD, : arguments imply differing number of rows: 202, 0 The data I am using is: Subject BiomR Spp Capas Litter Herbs LitterD MaxCanH DDifSp DSSp Slope CanDens NearestSp 1 140.74 Qfa 2 1.460 0 0.778 8 70 3.663 28 2.280 Ear 2 7.26 Aun 2 0.660 0 0.477 8 110 3.988 34 2.476 Ear 3 68.72 Qfa 2 1.019 0 1.000 8 48 2.300 48 2.476 Ear 4 0.13 Vti 2 1.719 0 0.903 4 55 4.141 28 3.258 Qco 5 2.32 Vti 2 1.719 0 0.954 4 65 3.984 32 3.051 Aun 6 2.97 Vti 2 1.719 0 0.954 6 201 3.642 22 2.000 Qfa 7 0.16 Qfa 2 1.238 2 0.778 6 72 3.105 20 1.566 Vti 8 1.76 Qfa 2 1.145 0 0.954 6 67 3.383 22 2.052 Vti 9 0.35 Qfa 3 1.092 2 0.778 6 65 3.557 30 2.106 Vti 10 0.15 Qfa 2 1.092 2 0.778 6 42 3.464 14 2.106 Vti 11 107.33 Qfa 3 1.145 5 0.903 8 147 4.035 24 2.220 Vti 12 12.32 Vti 3 1.145 5 1.000 6 208 3.464 28 2.220 Qfa 13 1.82 Vti 3 1.145 5 0.903 6 251 3.458 20 2.220 Qfa 14 1.84 Vti 1 1.019 5 0.602 6 88 3.960 28 1.363 Aun 15 3.25 Vti 2 1.719 0 0.778 6 70 4.319 14 2.621 Aun 16 3.60 Vti 1 1.460 0 0.954 6 53 4.186 26 1.902 Aun 17 0.69 Vti 2 1.238 5 0.845 4 184 3.856 44 2.547 Aun 18 1.04 Vti 1 1.019 5 0.602 4 144 3.911 32 2.052 Aun 19 0.08 Vti 2 1.460 0 0.699 6 93 3.956 36 2.547 Qco 20 10.43 Vti 2 1.145 5 0.903 6 70 3.919 23 3.258 Qco 21 0.69 Vti 3 1.145 5 0.845 8 120 4.023 30 3.051 Ear 22 13.47 Vti 3 1.460 2 0.811 8 39 3.370 42 3.152 Ear 23 2.83 Vti 2 1.019 5 0.845 6 120 4.102 24 3.258 Ear 24 1.26 Vti 2 1.019 5 0.903 6 153 4.116 30 3.152 Ear 25 0.25 Qfa 2 1.145 5 0.845 6 106 4.210 38 2.699 Qco 26 28.27 Vti 2 0.913 10 0.845 6 203 4.688 32 1.566 Qco 27 0.88 Vti 2 1.460 2 0.845 8 52 4.464 30 3.051 Qfa 28 0.08 Vti 2 1.311 0 0.477 8 86 4.486 48 2.956 Qfa 29 1.13 Vti 3 1.019 5 0.845 8 54 4.291 40 3.492 Qfa 30 11.03 Vti 2 0.821 0 0.903 4 130 4.606 42 2.699 Ear 31 0.63 Vti 2 0.821 5 0.845 4 130 4.464 44 2.699 Ear 32 0.97 Vti 2 0.737 0 0.845 4 123 4.562 34 2.699 Ear 33 4.94 Vti 2 0.737 0 0.903 4 123 4.522 48 2.699 Ear 34 2.26 Vti 2 0.821 5 0.778 4 114 4.478 46 2.699 Ear 35 0.94 Vti 2 0.660 0 0.903 4 144 4.516 31 2.699 Ear 36 0.69 Vti 2 0.589 0 0.699 4 146 4.551 35 2.699 Ear 37 0.13 Vti 3 1.019 0 0.845 8 48 4.362 14 2.343 Qfa 38 2.12 Vti 2 0.737 0 1.041 8 52 4.054 24 2.956 Qfa 39 1.77 Vti 2 0.913 0 0.903 8 56 5.198 6 2.621 Ear 40 0.32 Vti 2 1.145 5 0.954 8 118 5.138 35 3.258 Ear 41 0.11 Vti 2 1.019 0 0.602 8 84 5.237 20 2.621 Ear 42 1.57 Vti 1 0.913 0 0.954 6 137 5.038 12 3.492 Qco 43 1.77 Vti 3 0.737 0 0.954 6 141 5.026 16 3.371 Qco 44 0.17 Vti 2 0.913 0 1.000 8 69 4.901 24 3.258 Qco 45 0.41 Vti 3 1.092 2 0.954 8 81 5.129 44 4.457 Qfa 46 2.62 Vti 1 0.913 0 0.845 4 114 5.047 34 4.457 Ear 47 0.09 Vti 3 0.975 2 0.954 8 98 4.924 20 3.492 Aun 48 0.12 Vti 4 1.311 5 0.845 8 78 4.748 26 3.761 Aun 49 1.70 Vti 3 0.975 2 1.000 8 95 5.146 36 4.457 Qfa 50 14.49 Qfa 1 1.719 0 0.778 6 37 2.962 32 1.766 Pan 51 0.09 Vti 2 1.311 0 0.778 6 56 2.872 20 1.950 Pan 52 2.12 Qfa 2 1.460 0 0.845 6 203 3.097 18 3.152 Vti 53 0.23 Qfa 2 1.238 2 0.778 8 86 2.190 30 2.476 Ear 54 5.36 Qfa 2 0.975 0 0.954 6 134 3.409 42 4.684 Vti 55 0.41 Vti 2 1.145 5 0.845 6 108 3.890 36 4.945 Qco 56 0.19 Vti 1 1.719 0 0.845 6 42 4.130 35 3.492 Qco 57 15.59 Vti 3 1.719 0 1.114 6 91 4.386 16 4.257 Ear 58 3.25 Vti 3 1.719 0 0.903 6 85 4.275 36 4.257 Ear 59 2.32 Vti 3 1.460 0 0.954 6 91 4.223 32 4.257 Ear 60 4.24 Vti 3 1.719 0 1.041 6 36 4.386 42 4.257 Ear 61 31.49 Vti 3 1.719 0 1.176 6 78 4.371 43 4.257 Ear 62 2.97 Vti 3 0.786 2 0.954 6 71 3.988 22 4.076 Qco 63 0.50 Vti 3 0.706 2 0.903 6 76 4.134 20 4.076 Qco 64 20.20 Vti 2 1.719 0 1.079 6 62 3.557 18 5.640 Qfa 65 0.12 Vti 1 1.460 0 0.903 6 75 3.186 20 3.152 Qfa 66 0.10 Vti 1 1.719 0 0.903 6 90 3.154 20 3.152 Qfa 67 0.79 Vti 1 1.719 0 0.954 6 64 3.154 12 3.152 Ear 68 0.17 Vti 1 1.719 0 0.954 6
Re: [R] data.frame
Hi Your arguments has different length and therefore the error message data.frame is an object, which resembles a table from Excel, it has the same number of rows in each column From help page: A data frame, a matrix-like structure whose columns may be of differing types (numeric, logical, factor and character and so on). x1-1:5 x2-1:3 x3-1:10 data.frame(x1,x2,x3) Error in data.frame(x1, x2, x3) : arguments imply differing number of rows: 5, 3, 10 So you can recycle shorter vectors data.frame(cbind(x1,x2,x3)) or you can use list list(x1,x2,x3) I wonder how did you created your arguments? HTH Petr On 24 May 2006 at 13:05, Sara Mouro wrote: From: Sara Mouro [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Date sent: Wed, 24 May 2006 13:05:45 +0100 Subject:[R] data.frame Dear all, Does any one knows why should I get the following error message, when trying to do a simple data.frame?? DataF-data.frame(Subject,BiomR,Spp,Capas,Litter,Herbs,LitterD,MaxCanH ,DDifS p,DSSp,Slope, CanDens,NearestSp) Erro em data.frame(Subject, BiomR, Spp, Capas, Litter, Herbs, LitterD, : arguments imply differing number of rows: 202, 0 The data I am using is: Subject BiomR Spp Capas Litter Herbs LitterD MaxCanH DDifSp DSSp Slope CanDens NearestSp 1 140.74 Qfa 2 1.460 0 0.778 8 70 3.663 28 2.280 Ear 2 7.26 Aun 2 0.660 0 0.477 8 110 3.988 34 2.476 Ear 3 68.72 Qfa 2 1.019 0 1.000 8 48 2.300 48 2.476 Ear 4 0.13 Vti 2 1.719 0 0.903 4 55 4.141 28 3.258 Qco 5 2.32 Vti 2 1.719 0 0.954 4 65 3.984 32 3.051 Aun 6 2.97 Vti 2 1.719 0 0.954 6 201 3.642 22 2.000 Qfa 7 0.16 Qfa 2 1.238 2 0.778 6 72 3.105 20 1.566 Vti 8 1.76 Qfa 2 1.145 0 0.954 6 67 3.383 22 2.052 Vti 9 0.35 Qfa 3 1.092 2 0.778 6 65 3.557 30 2.106 Vti 10 0.15 Qfa 2 1.092 2 0.778 6 42 3.464 14 2.106 Vti 11 107.33 Qfa 3 1.145 5 0.903 8 147 4.035 24 2.220 Vti 12 12.32 Vti 3 1.145 5 1.000 6 208 3.464 28 2.220 Qfa 13 1.82 Vti 3 1.145 5 0.903 6 251 3.458 20 2.220 Qfa 14 1.84 Vti 1 1.019 5 0.602 6 88 3.960 28 1.363 Aun 15 3.25 Vti 2 1.719 0 0.778 6 70 4.319 14 2.621 Aun 16 3.60 Vti 1 1.460 0 0.954 6 53 4.186 26 1.902 Aun 17 0.69 Vti 2 1.238 5 0.845 4 184 3.856 44 2.547 Aun 18 1.04 Vti 1 1.019 5 0.602 4 144 3.911 32 2.052 Aun 19 0.08 Vti 2 1.460 0 0.699 6 93 3.956 36 2.547 Qco 20 10.43 Vti 2 1.145 5 0.903 6 70 3.919 23 3.258 Qco 21 0.69 Vti 3 1.145 5 0.845 8 120 4.023 30 3.051 Ear 22 13.47 Vti 3 1.460 2 0.811 8 39 3.370 42 3.152 Ear 23 2.83 Vti 2 1.019 5 0.845 6 120 4.102 24 3.258 Ear 24 1.26 Vti 2 1.019 5 0.903 6 153 4.116 30 3.152 Ear 25 0.25 Qfa 2 1.145 5 0.845 6 106 4.210 38 2.699 Qco 26 28.27 Vti 2 0.913 10 0.845 6 203 4.688 32 1.566 Qco 27 0.88 Vti 2 1.460 2 0.845 8 52 4.464 30 3.051 Qfa 28 0.08 Vti 2 1.311 0 0.477 8 86 4.486 48 2.956 Qfa 29 1.13 Vti 3 1.019 5 0.845 8 54 4.291 40 3.492 Qfa 30 11.03 Vti 2 0.821 0 0.903 4 130 4.606 42 2.699 Ear 31 0.63 Vti 2 0.821 5 0.845 4 130 4.464 44 2.699 Ear 32 0.97 Vti 2 0.737 0 0.845 4 123 4.562 34 2.699 Ear 33 4.94 Vti 2 0.737 0 0.903 4 123 4.522 48 2.699 Ear 34 2.26 Vti 2 0.821 5 0.778 4 114 4.478 46 2.699 Ear 35 0.94 Vti 2 0.660 0 0.903 4 144 4.516 31 2.699 Ear 36 0.69 Vti 2 0.589 0 0.699 4 146 4.551 35 2.699 Ear 37 0.13 Vti 3 1.019 0 0.845 8 48 4.362 14 2.343 Qfa 38 2.12 Vti 2 0.737 0 1.041 8 52 4.054 24 2.956 Qfa 39 1.77 Vti
Re: [R] data.frame
Sara, You didn't read your data into R correctly. If your data are really in the form you posted (one long column of mixed data types and lots of blank lines), then I would: 1. remove the blank lines with my text editor and save (say, mydata.txt) 2. scan() the variable names into a vector nm - scan(mydata.txt, what = , nlines = 13) 3. scan() the data values into a list x - scan(mydata.txt, what = list(0,0,,0,0,0,0,0,0,0,0,0,), skip = 13) 4. attach the names names(x) - nm 5. convert to data frame DF - data.frame(x) (You really shouldn't post your whole data set; a couple of records would have been sufficient.) Peter Ehlers Sara Mouro wrote: Dear all, Does any one knows why should I get the following error message, when trying to do a simple data.frame?? DataF-data.frame(Subject,BiomR,Spp,Capas,Litter,Herbs,LitterD,MaxCanH,DDifS p,DSSp,Slope, CanDens,NearestSp) Erro em data.frame(Subject, BiomR, Spp, Capas, Litter, Herbs, LitterD, : arguments imply differing number of rows: 202, 0 The data I am using is: Subject BiomR Spp Capas Litter Herbs LitterD MaxCanH DDifSp DSSp Slope CanDens NearestSp 1 140.74 Qfa 2 1.460 0 0.778 8 70 3.663 28 2.280 Ear 2 7.26 Aun 2 0.660 0 0.477 8 110 3.988 34 2.476 Ear __ R-help@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
Re: [R] data.frame to list
Larry Howe [EMAIL PROTECTED] wants to: 1. read in a 2-column data file, e.g. status tab new db tab green title tab Most Significant Excursions 2. end up with an R list such that I can write e.g. lst$title and have R return Most Significant Excursions. I call this reading a hash table (because it consists of name/value pairs), and here's a function to do it. Note this function allows you to input a hash if you wish, and then override its values with the data file. The argument defaults assume a tab-delimited text file with a header row, which is ignored. read.hash - function(file, defaults=list(), header=TRUE, sep=\t, ...) { pl - read.table(file, as.is=TRUE, header=header, sep=sep, ...) for (i in seq(pl[[1]])) defaults[[pl[[1]][i]]] - pl[[2]][i] defaults } Also see the built-in read.dcf, which uses a different input format, but might suit your purpose. -- David Brahm ([EMAIL PROTECTED]) __ R-help@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
Re: [R] data.frame to list
On Tuesday April 4 2006 21:56, Gabor Grothendieck wrote: Try this: dd - read.table(myfile, as.is = TRUE) lst - as.list(dd[,2]) names(lst) - dd[,1] lst$title This (almost) works. I did this instead: p = read.delim(params.txt, as.is=T) lst = as.list(p[ ,1]) names(lst) = rownames(p) I know that in some cases column 1 of the data file becomes column 1 of the frame, and in other cases it becomes the rownames. I think that is the difference. To respond to David Brahms' mail, yes, a hash is what I'm after. I guess my perl orientation is evident. And to help all those who come after and may be googling for this, I add the following keywords. like a hash in perl similar to a perl hash perl hash in R That ought to do it. Thanks everyone for your fast and insightful help. Larry Howe __ R-help@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
[R] data.frame to list
Hi, I'm new to R, and I'm not a statistician (stunned silence). I am trying to do the following: 1. read in a 2-column data file, e.g. status new db green title Most Significant Excursions 2. end up with an R list such that I can write e.g. lst$title and have R return Most Significant Excursions. I know I could do this by coding lst = list(title=Most Significant Excursions) however I would like to populate the list at runtime from a data file. I have tried df = read.delim(params.txt, as.is=T) and that gives me a data frame with the data in it. It seems to be a 2-element list where the first element is the first column of data and the second element is the second column of data. Not what I want. Maybe this is a related question: what's the relation between names, dimnames, row.name, and rownames? Is there any way to select records out of a data frame or vector based on any of these attributes? Thanks, Larry Howe __ R-help@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
Re: [R] data.frame to list
Try this: dd - read.table(myfile, as.is = TRUE) lst - as.list(dd[,2]) names(lst) - dd[,1] lst$title For a data frame (but not for a matrix) the names are the same as the colnames and dimnames is a two-element list consisting of the rownames and colnames. Try this: DF - data.frame(A = 1:5, B = 11:15) rownames(DF) - letters[1:5] names(DF) colnames(DF) rownames(DF) dimnames(DF) DF[c(a, b),] DF[,B] DF$B On 4/4/06, Larry Howe [EMAIL PROTECTED] wrote: Hi, I'm new to R, and I'm not a statistician (stunned silence). I am trying to do the following: 1. read in a 2-column data file, e.g. status new db green title Most Significant Excursions 2. end up with an R list such that I can write e.g. lst$title and have R return Most Significant Excursions. I know I could do this by coding lst = list(title=Most Significant Excursions) however I would like to populate the list at runtime from a data file. I have tried df = read.delim(params.txt, as.is=T) and that gives me a data frame with the data in it. It seems to be a 2-element list where the first element is the first column of data and the second element is the second column of data. Not what I want. Maybe this is a related question: what's the relation between names, dimnames, row.name, and rownames? Is there any way to select records out of a data frame or vector based on any of these attributes? Thanks, Larry Howe __ R-help@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 __ R-help@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
Re: [R] data.frame to list
You might want to consider the use of 'attr' to assign attributes to an object. That way you can keep your object as a data.frame: attr(x,title) - Most Significant attr(x,title) [1] Most Significant On 4/4/06, Larry Howe [EMAIL PROTECTED] wrote: Hi, I'm new to R, and I'm not a statistician (stunned silence). I am trying to do the following: 1. read in a 2-column data file, e.g. status new db green title Most Significant Excursions 2. end up with an R list such that I can write e.g. lst$title and have R return Most Significant Excursions. I know I could do this by coding lst = list(title=Most Significant Excursions) however I would like to populate the list at runtime from a data file. I have tried df = read.delim(params.txt, as.is=T) and that gives me a data frame with the data in it. It seems to be a 2-element list where the first element is the first column of data and the second element is the second column of data. Not what I want. Maybe this is a related question: what's the relation between names, dimnames, row.name, and rownames? Is there any way to select records out of a data frame or vector based on any of these attributes? Thanks, Larry Howe __ R-help@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 -- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@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
Re: [R] data.frame() size
That explains it. Thanks. I don't need rownames though, as I'll only ever use integer subscripts. Is there anyway to drop them, or even better not create them in the first place? The memory saved (90%) by not having them and 10 times speed up would be very useful. I think I need a data.frame rather than a matrix because I have columns of different types in real life. rownames(d) = NULL Error in dimnames-.data.frame(`*tmp*`, value = list(NULL, c(a, b : invalid 'dimnames' given for data frame -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Dalgaard Sent: 08 December 2005 18:57 To: Matthew Dowle Cc: 'r-help@stat.math.ethz.ch' Subject: Re: [R] data.frame() size Matthew Dowle [EMAIL PROTECTED] writes: Hi, In the example below why is d 10 times bigger than m, according to object.size ? It also takes around 10 times as long to create, which fits with object.size() being truthful. gcinfo(TRUE) also indicates a great deal more garbage collector activity caused by data.frame() than matrix(). $ R --vanilla nr = 100 system.time(m-matrix(integer(1), nrow=nr, ncol=2)) [1] 0.22 0.01 0.23 0.00 0.00 system.time(d-data.frame(a=integer(nr), b=integer(nr))) [1] 2.81 0.20 3.01 0.00 0.00 # 10 times longer dim(m) [1] 100 2 dim(d) [1] 100 2 # same dimensions storage.mode(m) [1] integer sapply(d, storage.mode) a b integer integer # same storage.mode object.size(m)/1024^2 [1] 7.629616 object.size(d)/1024^2 [1] 76.29482 # but 10 times bigger sum(sapply(d, object.size))/1024^2 [1] 7.629501 # or is it ?If its not really 10 times bigger, why 10 times longer above ? Row names!! r - as.character(1:1e6) object.size(r) [1] 7256 object.size(r)/1024^2 [1] 68.6646 'nuff said? -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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
[R] data.frame() size
Hi, In the example below why is d 10 times bigger than m, according to object.size ? It also takes around 10 times as long to create, which fits with object.size() being truthful. gcinfo(TRUE) also indicates a great deal more garbage collector activity caused by data.frame() than matrix(). $ R --vanilla nr = 100 system.time(m-matrix(integer(1), nrow=nr, ncol=2)) [1] 0.22 0.01 0.23 0.00 0.00 system.time(d-data.frame(a=integer(nr), b=integer(nr))) [1] 2.81 0.20 3.01 0.00 0.00# 10 times longer dim(m) [1] 100 2 dim(d) [1] 100 2 # same dimensions storage.mode(m) [1] integer sapply(d, storage.mode) a b integer integer # same storage.mode object.size(m)/1024^2 [1] 7.629616 object.size(d)/1024^2 [1] 76.29482# but 10 times bigger sum(sapply(d, object.size))/1024^2 [1] 7.629501# or is it ?If its not really 10 times bigger, why 10 times longer above ? version platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major2 minor1.1 year 2005 month06 day 20 language R Many thanks in advance! Matthew [[alternative HTML version deleted]] __ R-help@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
Re: [R] data.frame() size
Matthew Dowle [EMAIL PROTECTED] writes: Hi, In the example below why is d 10 times bigger than m, according to object.size ? It also takes around 10 times as long to create, which fits with object.size() being truthful. gcinfo(TRUE) also indicates a great deal more garbage collector activity caused by data.frame() than matrix(). $ R --vanilla nr = 100 system.time(m-matrix(integer(1), nrow=nr, ncol=2)) [1] 0.22 0.01 0.23 0.00 0.00 system.time(d-data.frame(a=integer(nr), b=integer(nr))) [1] 2.81 0.20 3.01 0.00 0.00 # 10 times longer dim(m) [1] 100 2 dim(d) [1] 100 2 # same dimensions storage.mode(m) [1] integer sapply(d, storage.mode) a b integer integer # same storage.mode object.size(m)/1024^2 [1] 7.629616 object.size(d)/1024^2 [1] 76.29482 # but 10 times bigger sum(sapply(d, object.size))/1024^2 [1] 7.629501 # or is it ?If its not really 10 times bigger, why 10 times longer above ? Row names!! r - as.character(1:1e6) object.size(r) [1] 7256 object.size(r)/1024^2 [1] 68.6646 'nuff said? -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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
Re: [R] data.frame-question]
First a general comment on posting style, could you please be more specific about where the error occurs as without this it is very difficult to identify what the problem is. Now concerning your problem. When I tried the code I posted yesterday I thought it worked fine. I've tried it again now and found that the data.frame TAB3 actually only has one column and the names A, B etc are actually interpreted as the row names. Since there is only one column the 'colnames(TAB3) -' fails when you give it a vector with two components. I think that if you display it without renaming the columns then it still displays the correct results though. I also tested it with including NA's and it worked fine. I'm quite a newbie myself so I don't know how you can't tell you how to return the result into a two column data.frame. For completeness, here is the code I used to test. Name - c(rep(A, 3), rep(B, 5), C) Number - rep(1, 8) Number[9] - NA TAB1 - data.frame(Name, Number) TAB1 Name Number 1A 1 2A 1 3A 1 4B 1 5B 1 6B 1 7B 1 8B 1 9C NA TAB3 - with(TAB1, tapply(Number, Name, sum, na.rm=TRUE)) TAB3 A B C 3 5 0 TAB3 - as.data.frame(TAB3) TAB3 TAB3 A3 B5 C0 colnames(TAB3) - c(Name_singular, Sum) Error in dimnames-.data.frame(`*tmp*`, value = list(c(A, B, C : invalid 'dimnames' given for data frame TAB3 TAB3 A3 B5 C0 str(TAB3) `data.frame': 3 obs. of 1 variable: $ TAB3: num [, 1:3] 3 5 0 ..- attr(*, dimnames)=List of 1 .. ..$ : chr A B C version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.0 year 2005 month10 day 06 svn rev 35749 language R -Original Message- From: Michael Graber [mailto:[EMAIL PROTECTED] Sent: 27 October 2005 12:43 AM To: [EMAIL PROTECTED] Subject: Re: Re: [R] data.frame-question] This is what I am looking for, but I still get an error message, that my arguments are not of the same length. How can I avoid this error message? Maybe I should add, that there are also NA´s in the second column, but I tried to ignore them by na.rm=TRUE. Thanks in advance, Michael Graber Michael Graber schrieb: -- -- Betreff: RE: [R] data.frame-question Von: Brandt, T. (Tobias) [EMAIL PROTECTED] Datum: Wed, 26 Oct 2005 09:20:23 +0200 An: 'r-help@stat.math.ethz.ch' r-help@stat.math.ethz.ch An: 'r-help@stat.math.ethz.ch' r-help@stat.math.ethz.ch CC: 'Michael Graber' [EMAIL PROTECTED] Is TAB3 - as.data.frame(with(TAB1, tapply(Number, Name, sum))) colnames(TAB3) - c(Name_singular, Sum) what you are looking for? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Graber Sent: 25 October 2005 09:45 PM To: R-Mailingliste Subject: [R] data.frame-question Dear R-List, I am very new to R and programming itself, so my question may be easy to answer for you. I tried a lot and read through the manuals, but I still have the following problem: I have 2 data-frames: Number-as.numeric (Number) Name-as.character (Name) TAB1-data.frame (Name,Number) - it looks like this:- Name Number A 2 A 3 A 6 B 8 B 12 B 7 C 8 D 90 E 12 E 45 ... Name_singular-as.character (Name_singular) TAB2-data.frame (Name_singular) # it looks like this: Name_singular A B C D E -My result should be a data-frame, where the first column is Name_singular and the second column should be the sum of the numbers where Name ==Name_singular.- For example: TAB3: Name_singular Sum A 11 B 27 ... - I tried it with for-loops, but I think there must be an easier way.- I would be very grateful for your help, Michael Graber __ R-help@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 -- -- Nedbank Limited Reg No 1951/09/06 Directors: WAM Clewlow (Chairman) Prof MM Katz (Vice-chairman) ML Ndlovu (Vice-chairman) TA Boardman (Chief Executive) CJW Ball MWT Brown RG Cottrell BE Davison N Dennis (British) MA Enus-Brey Prof B de L Figaji RM Head (British) RJ Khoza JB Magwaza ME Mkwanazi JVF Roberts (British) CML Savage GT Serobe JH Sutcliffe (British) Company Secretary: GS Nienaber 16.08.2005 This email and any accompanying attachments may contain confidential and proprietary information. This information is private and protected by law and, accordingly, if you are not the intended recipient, you are requested to delete this entire communication
Re: [R] data.frame-question]
Hi quite near using aggregate it is possible to reach what you want TAB3 - with(TAB1, aggregate(Number, list(Name_singular=Name), sum, na.rm=TRUE)) see str(TAB3) `data.frame': 3 obs. of 2 variables: $ Name_singular: Factor w/ 3 levels A,B,C: 1 2 3 $ x: num 3 5 0 HTH Petr On 27 Oct 2005 at 8:47, Brandt, T. (Tobias) wrote: From: Brandt, T. (Tobias) [EMAIL PROTECTED] To: 'Michael Graber' [EMAIL PROTECTED], 'r-help@stat.math.ethz.ch' r-help@stat.math.ethz.ch Date sent: Thu, 27 Oct 2005 08:47:45 +0200 Subject:Re: [R] data.frame-question] First a general comment on posting style, could you please be more specific about where the error occurs as without this it is very difficult to identify what the problem is. Now concerning your problem. When I tried the code I posted yesterday I thought it worked fine. I've tried it again now and found that the data.frame TAB3 actually only has one column and the names A, B etc are actually interpreted as the row names. Since there is only one column the 'colnames(TAB3) -' fails when you give it a vector with two components. I think that if you display it without renaming the columns then it still displays the correct results though. I also tested it with including NA's and it worked fine. I'm quite a newbie myself so I don't know how you can't tell you how to return the result into a two column data.frame. For completeness, here is the code I used to test. Name - c(rep(A, 3), rep(B, 5), C) Number - rep(1, 8) Number[9] - NA TAB1 - data.frame(Name, Number) TAB1 Name Number 1A 1 2A 1 3A 1 4B 1 5B 1 6B 1 7B 1 8B 1 9C NA TAB3 - with(TAB1, tapply(Number, Name, sum, na.rm=TRUE)) TAB3 A B C 3 5 0 TAB3 - as.data.frame(TAB3) TAB3 TAB3 A3 B5 C0 colnames(TAB3) - c(Name_singular, Sum) Error in dimnames-.data.frame(`*tmp*`, value = list(c(A, B, C : invalid 'dimnames' given for data frame TAB3 TAB3 A3 B5 C0 str(TAB3) `data.frame': 3 obs. of 1 variable: $ TAB3: num [, 1:3] 3 5 0 ..- attr(*, dimnames)=List of 1 .. ..$ : chr A B C version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.0 year 2005 month10 day 06 svn rev 35749 language R -Original Message- From: Michael Graber [mailto:[EMAIL PROTECTED] Sent: 27 October 2005 12:43 AM To: [EMAIL PROTECTED] Subject: Re: Re: [R] data.frame-question] This is what I am looking for, but I still get an error message, that my arguments are not of the same length. How can I avoid this error message? Maybe I should add, that there are also NA´s in the second column, but I tried to ignore them by na.rm=TRUE. Thanks in advance, Michael Graber Michael Graber schrieb: -- -- Betreff: RE: [R] data.frame-question Von: Brandt, T. (Tobias) [EMAIL PROTECTED] Datum: Wed, 26 Oct 2005 09:20:23 +0200 An: 'r-help@stat.math.ethz.ch' r-help@stat.math.ethz.ch An: 'r-help@stat.math.ethz.ch' r-help@stat.math.ethz.ch CC: 'Michael Graber' [EMAIL PROTECTED] Is TAB3 - as.data.frame(with(TAB1, tapply(Number, Name, sum))) colnames(TAB3) - c(Name_singular, Sum) what you are looking for? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Graber Sent: 25 October 2005 09:45 PM To: R-Mailingliste Subject: [R] data.frame-question Dear R-List, I am very new to R and programming itself, so my question may be easy to answer for you. I tried a lot and read through the manuals, but I still have the following problem: I have 2 data-frames: Number-as.numeric (Number) Name-as.character (Name) TAB1-data.frame (Name,Number) - it looks like this:- Name Number A 2 A 3 A 6 B 8 B 12 B 7 C 8 D 90 E 12 E 45 ... Name_singular-as.character (Name_singular) TAB2-data.frame (Name_singular) # it looks like this: Name_singular A B C D E -My result should be a data-frame, where the first column is Name_singular and the second column should be the sum of the numbers where Name ==Name_singular.- For example: TAB3: Name_singular Sum A 11 B 27 ... - I tried it with for-loops, but I think there must be an easier way.- I would be very grateful for your help, Michael Graber __ R-help@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
Re: [R] data.frame-question
Is TAB3 - as.data.frame(with(TAB1, tapply(Number, Name, sum))) colnames(TAB3) - c(Name_singular, Sum) what you are looking for? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Graber Sent: 25 October 2005 09:45 PM To: R-Mailingliste Subject: [R] data.frame-question Dear R-List, I am very new to R and programming itself, so my question may be easy to answer for you. I tried a lot and read through the manuals, but I still have the following problem: I have 2 data-frames: Number-as.numeric (Number) Name-as.character (Name) TAB1-data.frame (Name,Number) - it looks like this:- Name Number A 2 A 3 A 6 B 8 B 12 B 7 C 8 D 90 E 12 E 45 ... Name_singular-as.character (Name_singular) TAB2-data.frame (Name_singular) # it looks like this: Name_singular A B C D E -My result should be a data-frame, where the first column is Name_singular and the second column should be the sum of the numbers where Name ==Name_singular.- For example: TAB3: Name_singular Sum A 11 B 27 ... - I tried it with for-loops, but I think there must be an easier way.- I would be very grateful for your help, Michael Graber __ R-help@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 Nedbank Limited Reg No 1951/09/06 Directors: WAM Clewlow (Chairman) Prof MM Katz (Vice-chairman) ML Ndlovu (Vice-chairman) TA Boardman (Chief Executive) CJW Ball MWT Brown RG Cottrell BE Davison N Dennis (British) MA Enus-Brey Prof B de L Figaji RM Head (British) RJ Khoza JB Magwaza ME Mkwanazi JVF Roberts (British) CML Savage GT Serobe JH Sutcliffe (British) Company Secretary: GS Nienaber 16.08.2005 This email and any accompanying attachments may contain confidential and proprietary information. This information is private and protected by law and, accordingly, if you are not the intended recipient, you are requested to delete this entire communication immediately and are notified that any disclosure, copying or distribution of or taking any action based on this information is prohibited. Emails cannot be guaranteed to be secure or free of errors or viruses. The sender does not accept any liability or responsibility for any interception, corruption, destruction, loss, late arrival or incompleteness of or tampering or interference with any of the information contained in this email or for its incorrect delivery or non-delivery for whatsoever reason or for its effect on any electronic device of the recipient. If verification of this email or any attachment is required, please request a hard-copy version. [[alternative HTML version deleted]] __ R-help@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
[R] data.frame-question
Dear R-List, I am very new to R and programming itself, so my question may be easy to answer for you. I tried a lot and read through the manuals, but I still have the following problem: I have 2 data-frames: Number-as.numeric (Number) Name-as.character (Name) TAB1-data.frame (Name,Number) - it looks like this:- Name Number A 2 A 3 A 6 B 8 B 12 B 7 C 8 D 90 E 12 E 45 … Name_singular-as.character (Name_singular) TAB2-data.frame (Name_singular) # it looks like this: Name_singular A B C D E -My result should be a data-frame, where the first column is Name_singular and the second column should be the sum of the numbers where Name ==Name_singular.- For example: TAB3: Name_singular Sum A 11 B 27 … - I tried it with for-loops, but I think there must be an easier way.- I would be very grateful for your help, Michael Graber __ R-help@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
Re: [R] data.frame-question
Welcome to R. See ?merge then ?aggregate or require(Hmisc) ?summarize or ?by You can probably find many examples in the archives, if needed. -Original Message- From: Michael Graber [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 25, 2005 3:45 PM To: R-Mailingliste Subject: [R] data.frame-question Dear R-List, I am very new to R and programming itself, so my question may be easy to answer for you. I tried a lot and read through the manuals, but I still have the following problem: I have 2 data-frames: Number-as.numeric (Number) Name-as.character (Name) TAB1-data.frame (Name,Number) - it looks like this:- Name Number A 2 A 3 A 6 B 8 B 12 B 7 C 8 D 90 E 12 E 45 … Name_singular-as.character (Name_singular) TAB2-data.frame (Name_singular) # it looks like this: Name_singular A B C D E -My result should be a data-frame, where the first column is Name_singular and the second column should be the sum of the numbers where Name ==Name_singular.- For example: TAB3: Name_singular Sum A 11 B 27 … - I tried it with for-loops, but I think there must be an easier way.- I would be very grateful for your help, Michael Graber __ R-help@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 __ R-help@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
[R] data.frame error using sem package
I keep getting this error when I try to use the sem package. I and another person who has successfully used the sem package for similar analysis (fMRI effective connectivity) cannot figure out what is wrong with my code. I would appreciate any suggestions. The error message: Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))), par.code) : arguments imply differing number of rows: 6, 0 In addition: Warning message: Could not compute QR decomposition of Hessian. Optimization probably did not converge. in: sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, Thank you, Suzanne __ R-help@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
Re: [R] data.frame error using sem package
Suzanne Witt wrote: I keep getting this error when I try to use the sem package. I and another person who has successfully used the sem package for similar analysis (fMRI effective connectivity) cannot figure out what is wrong with my code. I would appreciate any suggestions. It is almost impossible to help if you do not specify a toy example that shows how you produced that error message. Please read the psoting guide which tells you how to specify such examples most appropriately in order to get a good answer. Uwe Ligges The error message: Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))), par.code) : arguments imply differing number of rows: 6, 0 In addition: Warning message: Could not compute QR decomposition of Hessian. Optimization probably did not converge. in: sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, Thank you, Suzanne __ R-help@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 __ R-help@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
[R] data.frame error using sem package
I am trying to use sem to measure effective connectivity among four brain regions. I have pasted the code that I am trying to run since that seems easier than trying to come up with another example. The input data is time series data taken from SPM; they are each 1x121 columns of numbers. I get the error either when I source the whole code, or if I enter it line by line when I go to get the summary. Thanks, Suzanne library(sem) # Load the region timecourses. lsma1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_LSMA.dat) rsma1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_RSMA.dat) lmc1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_LM1.dat) rmc1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_RM1.dat) # Combine all the timecourses from each session into a single data frame and name the columns appropriately. lcomf - cbind(lsma1, rsma1, lmc1, rmc1) names(lcomf) - c(LSMA, RSMA, LM1, RM1) # Type this at the command line to see a summary of your data str(lcomf) # Set up the structural equation model. p.ram - matrix(c( 'LM1 - LSMA', 'LM1 - LSMA', NA, 'LSMA - RSMA', 'LSMA - RSMA', NA, 'RSMA - RM1', 'RSMA - RM1', NA, 'LSMA - LSMA', 'LSMA - LSMA', NA, 'RSMA - RSMA', 'RSMA - RSMA', NA, 'RM1 - RM1', 'RM1 - RM1', NA), ncol = 3, byrow = TRUE) # Tell which variables are exogenous ('fixed'). p.fixed - c('LM1') # Do the fitting for session 1. C - cor(lcomf) nt - dim(lcomf)[1] #attach(lcomf) lcomf.results - sem(p.ram, C, nt, obs.variables = rownames(C), fixed.x = p.fixed) # Check out the results using the summary function summary(lcomf.results) [[alternative HTML version deleted]] __ R-help@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
Re: [R] data.frame error using sem package
Dear Suzanne, Take a look at your model specification: p.ram [,1][,2][,3] [1,] LM1 - LSMA LM1 - LSMA NA [2,] LSMA - RSMA LSMA - RSMA NA [3,] RSMA - RM1 RSMA - RM1 NA [4,] LSMA - LSMA LSMA - LSMA NA [5,] RSMA - RSMA RSMA - RSMA NA [6,] RM1 - RM1 RM1 - RM1 NA This matrix should have three columns, the first giving the path, the second the name of the corresponding parameter, and the third the start value for the parameter (or NA if you want sem() to compute a start value). You've apparently left out the parameter names. Please see the sem examples for details and the paper at http://socserv.socsci.mcmaster.ca/jfox/sem-package.pdf. I hope this helps, John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Suzanne Witt Sent: Thursday, October 06, 2005 2:55 PM To: r-help@stat.math.ethz.ch Subject: [R] data.frame error using sem package I am trying to use sem to measure effective connectivity among four brain regions. I have pasted the code that I am trying to run since that seems easier than trying to come up with another example. The input data is time series data taken from SPM; they are each 1x121 columns of numbers. I get the error either when I source the whole code, or if I enter it line by line when I go to get the summary. Thanks, Suzanne library(sem) # Load the region timecourses. lsma1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_LSMA.dat) rsma1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_RSMA.dat) lmc1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_LM1.dat) rmc1 - read.table(/Users/witt/parkinsons/rmrkm010905/R_files/ 010905_lcomf_RM1.dat) # Combine all the timecourses from each session into a single data frame and name the columns appropriately. lcomf - cbind(lsma1, rsma1, lmc1, rmc1) names(lcomf) - c(LSMA, RSMA, LM1, RM1) # Type this at the command line to see a summary of your data str(lcomf) # Set up the structural equation model. p.ram - matrix(c( 'LM1 - LSMA', 'LM1 - LSMA', NA, 'LSMA - RSMA', 'LSMA - RSMA', NA, 'RSMA - RM1', 'RSMA - RM1', NA, 'LSMA - LSMA', 'LSMA - LSMA', NA, 'RSMA - RSMA', 'RSMA - RSMA', NA, 'RM1 - RM1', 'RM1 - RM1', NA), ncol = 3, byrow = TRUE) # Tell which variables are exogenous ('fixed'). p.fixed - c('LM1') # Do the fitting for session 1. C - cor(lcomf) nt - dim(lcomf)[1] #attach(lcomf) lcomf.results - sem(p.ram, C, nt, obs.variables = rownames(C), fixed.x = p.fixed) # Check out the results using the summary function summary(lcomf.results) [[alternative HTML version deleted]] __ R-help@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 __ R-help@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
[R] data.frame to character
Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame L3 - LETTERS[1:3] L10 - LETTERS[1:10] d - data.frame(cbind(x=c(XYZ), y=L10), fac=sample(L3, 10, repl=TRUE)) d x y fac 1 XYZ A A 2 XYZ B A 3 XYZ C A 4 XYZ D A 5 XYZ E B 6 XYZ F C 7 XYZ G A 8 XYZ H C 9 XYZ I B 10 XYZ J A str(d) `data.frame': 10 obs. of 3 variables: $ x : Factor w/ 1 level XYZ: 1 1 1 1 1 1 1 1 1 1 $ y : Factor w/ 10 levels A,B,C,D,..: 1 2 3 4 5 6 7 8 9 10 $ fac: Factor w/ 3 levels A,B,C: 1 1 1 1 2 3 1 3 2 1 d[3,] x y fac 3 XYZ C A as.character(d[3,]) [1] 1 3 1 I think as.character the result something like [3] XYZ C A I don't know how to convert it. Any help gratefully received. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@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
Re: [R] data.frame to character
Is this what you want? d[] - lapply(d, as.character) str(d) `data.frame': 10 obs. of 3 variables: $ x : chr XYZ XYZ XYZ XYZ ... $ y : chr A B C D ... $ fac: chr B A C B ... Andy From: Muhammad Subianto Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame L3 - LETTERS[1:3] L10 - LETTERS[1:10] d - data.frame(cbind(x=c(XYZ), y=L10), fac=sample(L3, 10, repl=TRUE)) d x y fac 1 XYZ A A 2 XYZ B A 3 XYZ C A 4 XYZ D A 5 XYZ E B 6 XYZ F C 7 XYZ G A 8 XYZ H C 9 XYZ I B 10 XYZ J A str(d) `data.frame': 10 obs. of 3 variables: $ x : Factor w/ 1 level XYZ: 1 1 1 1 1 1 1 1 1 1 $ y : Factor w/ 10 levels A,B,C,D,..: 1 2 3 4 5 6 7 8 9 10 $ fac: Factor w/ 3 levels A,B,C: 1 1 1 1 2 3 1 3 2 1 d[3,] x y fac 3 XYZ C A as.character(d[3,]) [1] 1 3 1 I think as.character the result something like [3] XYZ C A I don't know how to convert it. Any help gratefully received. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@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 __ R-help@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
Re: [R] data.frame to character
On 6/10/05, Muhammad Subianto [EMAIL PROTECTED] wrote: Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame L3 - LETTERS[1:3] L10 - LETTERS[1:10] d - data.frame(cbind(x=c(XYZ), y=L10), fac=sample(L3, 10, repl=TRUE)) d[] - as.matrix(d) __ R-help@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
Re: [R] data.frame to character - thanks
Dear all, Thank you very much for your help. I would like to thank Andy Liaw and Gabor Grothendieck for their fast help. Regards, Muhammad Subianto On this day 6/10/2005 2:30 PM, Liaw, Andy wrote: Is this what you want? d[] - lapply(d, as.character) str(d) `data.frame': 10 obs. of 3 variables: $ x : chr XYZ XYZ XYZ XYZ ... $ y : chr A B C D ... $ fac: chr B A C B ... Andy On this day 6/10/2005 2:35 PM, Gabor Grothendieck wrote: On 6/10/05, Muhammad Subianto [EMAIL PROTECTED] wrote: Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame L3 - LETTERS[1:3] L10 - LETTERS[1:10] d - data.frame(cbind(x=c(XYZ), y=L10), fac=sample(L3, 10, repl=TRUE)) d[] - as.matrix(d) On this day 6/10/2005 2:23 PM, Muhammad Subianto wrote: Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame L3 - LETTERS[1:3] L10 - LETTERS[1:10] d - data.frame(cbind(x=c(XYZ), y=L10), fac=sample(L3, 10, repl=TRUE)) d x y fac 1 XYZ A A 2 XYZ B A 3 XYZ C A 4 XYZ D A 5 XYZ E B 6 XYZ F C 7 XYZ G A 8 XYZ H C 9 XYZ I B 10 XYZ J A str(d) `data.frame': 10 obs. of 3 variables: $ x : Factor w/ 1 level XYZ: 1 1 1 1 1 1 1 1 1 1 $ y : Factor w/ 10 levels A,B,C,D,..: 1 2 3 4 5 6 7 8 9 10 $ fac: Factor w/ 3 levels A,B,C: 1 1 1 1 2 3 1 3 2 1 d[3,] x y fac 3 XYZ C A as.character(d[3,]) [1] 1 3 1 I think as.character the result something like [3] XYZ C A I don't know how to convert it. Any help gratefully received. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@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 __ R-help@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
Re: [R] data.frame to character - thanks
Here is one minor improvement -- it does not overwrite the input: replace(d,,as.matrix(d)) On 6/10/05, Muhammad Subianto [EMAIL PROTECTED] wrote: Dear all, Thank you very much for your help. I would like to thank Andy Liaw and Gabor Grothendieck for their fast help. Regards, Muhammad Subianto On this day 6/10/2005 2:30 PM, Liaw, Andy wrote: Is this what you want? d[] - lapply(d, as.character) str(d) `data.frame': 10 obs. of 3 variables: $ x : chr XYZ XYZ XYZ XYZ ... $ y : chr A B C D ... $ fac: chr B A C B ... Andy On this day 6/10/2005 2:35 PM, Gabor Grothendieck wrote: On 6/10/05, Muhammad Subianto [EMAIL PROTECTED] wrote: Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame L3 - LETTERS[1:3] L10 - LETTERS[1:10] d - data.frame(cbind(x=c(XYZ), y=L10), fac=sample(L3, 10, repl=TRUE)) d[] - as.matrix(d) On this day 6/10/2005 2:23 PM, Muhammad Subianto wrote: Hi, Excuse me for this simple question. How to convert as.data.frame to as.character? ?data.frame L3 - LETTERS[1:3] L10 - LETTERS[1:10] d - data.frame(cbind(x=c(XYZ), y=L10), fac=sample(L3, 10, repl=TRUE)) d x y fac 1 XYZ A A 2 XYZ B A 3 XYZ C A 4 XYZ D A 5 XYZ E B 6 XYZ F C 7 XYZ G A 8 XYZ H C 9 XYZ I B 10 XYZ J A str(d) `data.frame': 10 obs. of 3 variables: $ x : Factor w/ 1 level XYZ: 1 1 1 1 1 1 1 1 1 1 $ y : Factor w/ 10 levels A,B,C,D,..: 1 2 3 4 5 6 7 8 9 10 $ fac: Factor w/ 3 levels A,B,C: 1 1 1 1 2 3 1 3 2 1 d[3,] x y fac 3 XYZ C A as.character(d[3,]) [1] 1 3 1 I think as.character the result something like [3] XYZ C A I don't know how to convert it. Any help gratefully received. Thank you very much in advance. Kindly regards, Muhammad Subianto __ R-help@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 __ R-help@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
[R] data.frame objects as seen by tapply
Dear all, I have encountered a bizarre ocurrence: tapply() does not treat the columns of data.frame[,cols] in the same way as those of data.frame[1:length(data.frame),cols]. Whilst for the latter it identifies the length of the column to be length(data.frame) in the former it does not seem to. I am enclosing the code where this happens. Any clues? asset.t - sapply( # asset[,sapply(asset,is.numeric),drop=T], # returns error Error in tapply(x, frame[row, index], FUN = sum, na.rm = TRUE) : arguments must have same length asset[1:length(asset),sapply(asset,is.numeric)], FUN = apply_cols, frame = asset, index = NAME ) # Function definitions apply_cols - function(x, frame, row = 1:length(frame), index) tapply( x, frame[row, index], FUN=sum, na.rm=TRUE ) -- Ivan Alves Mailto://[EMAIL PROTECTED] __ R-help@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
[R] data.frame, data types, and apply
Dear all, Here is an issue I often stumble on. 1- colunm types in data.frames. --- d - data.frame(x=as.character(c(a, b, c)), y=as.numeric(c(1, 2, 3))) d x y 1 a 1 2 b 2 3 c 3 is.numeric(d[1,2]) [1] TRUE is.numeric(d[1,1]) [1] FALSE apply(d, c(1,2), is.numeric) x y 1 FALSE FALSE 2 FALSE FALSE 3 FALSE FALSE --- All item in column y should be TRUE right? What should I do to apply a function only to numerics in d? (beside using nested 'for' loops) Thanks for your help, and for all the great software. Vincent Detours __ R-help@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
Re: [R] data.frame, data types, and apply
Vincent Detours wrote: Dear all, Here is an issue I often stumble on. 1- colunm types in data.frames. --- d - data.frame(x=as.character(c(a, b, c)), y=as.numeric(c(1, 2, 3))) d x y 1 a 1 2 b 2 3 c 3 is.numeric(d[1,2]) [1] TRUE is.numeric(d[1,1]) [1] FALSE apply(d, c(1,2), is.numeric) x y 1 FALSE FALSE 2 FALSE FALSE 3 FALSE FALSE --- All item in column y should be TRUE right? What should I do to apply a function only to numerics in d? (beside using nested 'for' loops) It is correct! d is a data.frame, but apply() works on matrices. So d is coerced to a matrix which means that there need to be only one mode - and that is character! Check the columns as in sapply(d, is.numeric) Uwe Ligges Thanks for your help, and for all the great software. Vincent Detours __ R-help@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 __ R-help@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
RE: [R] data.frame error message
At 09:47 PM 2/22/2005 -0500, Liaw, Andy wrote: Following the suggestions in the Posting Guide would help us to help you much better. What command(s) did you use to get the data into R? read.table(C:/.../persist.dat,col.names=c(a,b,etc.)) What does the `.dat' file look like? Itn was created in Word, as a plain text file. 6000 24 female 0.0014 1.4 1 3.47 0.25 2478.57 6000 168 female 0.0014 1.4 1 0.73 0.05 521.43 6000 96 female 0.0014 1.4 1 0.96 0.07 685.71 6000 168 female 0.0014 1.4 1 1.36 0.10 971.43 6000 24 female 0.0014 1.4 1 2.69 0.19 1921.43 6000 96 female 0.0014 1.4 1 0.76 0.05 542.86... What are `x' and `y'? 'x' is trt and 'y' is ppmtrans. I did subset commands to find all the males with ppmsamp above a certain value. persist[1:5,] dose trtsex massg massmg vol ppm perc ppmsamp 1 6000 24 female 0.00141.4 1 3.47 0.25 2478.57 2 6000 168 female 0.00141.4 1 0.73 0.05 521.43 3 6000 96female 0.00141.4 1 0.96 0.07 685.71 4 6000 168 female 0.00141.4 1 1.36 0.10 971.43 5 6000 24female 0.00141.4 12.69 0.19 1921.43 ...subsetting commands... ppmtrans-sqrt(sqrt(ppm.male.mark$ppmsamp)) persist.male-cbind(ppm.male.mark,ppmtrans) persist.male[1:5,] dose trt sex massg massmg vol ppm perc ppmsamp ppmtrans 27 6000 96 male 0.00121.2 1 1.82 0.15 1516.67 6.240549 55 6000 168 male 0.00121.2 1 0.90 0.08 750.00 5.233176 70 6000 168 male 0.00121.2 1 1.97 0.16 1641.67 6.365338 76 6000 96 male 0.00121.2 1 4.02 0.34 3350.00 7.607837 83 6000 168 male 0.00121.2 1 1.26 0.11 1050.00 5.692425 plot(trt,ppmtrans) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : variable lengths differ After my initial post, I found that if I specified the data set in the plot arguments, I could generate a boxplot. I then performed ANOVA on the response after creating factor levels for trt, and generated a stripchart showing the data in each of the three trts. But for future reference, if I need to do linear regression with a similar data set, I'd like to know what is happening. Thank you-- NH Ellis [[alternative HTML version deleted]] __ R-help@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
RE: [R] data.frame error message
From: Nic Ellis At 09:47 PM 2/22/2005 -0500, Liaw, Andy wrote: Following the suggestions in the Posting Guide would help us to help you much better. What command(s) did you use to get the data into R? read.table(C:/.../persist.dat,col.names=c(a,b,etc.)) What does the `.dat' file look like? Itn was created in Word, as a plain text file. 6000 24 female 0.0014 1.4 1 3.47 0.25 2478.57 6000 168 female 0.0014 1.4 1 0.73 0.05 521.43 6000 96 female 0.0014 1.4 1 0.96 0.07 685.71 6000 168 female 0.0014 1.4 1 1.36 0.10 971.43 6000 24 female 0.0014 1.4 1 2.69 0.19 1921.43 6000 96 female 0.0014 1.4 1 0.76 0.05 542.86... What are `x' and `y'? 'x' is trt and 'y' is ppmtrans. I did subset commands to find all the males with ppmsamp above a certain value. persist[1:5,] dose trtsex massg massmg vol ppm perc ppmsamp 1 6000 24 female 0.00141.4 1 3.47 0.25 2478.57 2 6000 168 female 0.00141.4 1 0.73 0.05 521.43 3 6000 96female 0.00141.4 1 0.96 0.07 685.71 4 6000 168 female 0.00141.4 1 1.36 0.10 971.43 5 6000 24female 0.00141.4 12.69 0.19 1921.43 ...subsetting commands... ppmtrans-sqrt(sqrt(ppm.male.mark$ppmsamp)) persist.male-cbind(ppm.male.mark,ppmtrans) persist.male[1:5,] dose trt sex massg massmg vol ppm perc ppmsamp ppmtrans 27 6000 96 male 0.00121.2 1 1.82 0.15 1516.67 6.240549 55 6000 168 male 0.00121.2 1 0.90 0.08 750.00 5.233176 70 6000 168 male 0.00121.2 1 1.97 0.16 1641.67 6.365338 76 6000 96 male 0.00121.2 1 4.02 0.34 3350.00 7.607837 83 6000 168 male 0.00121.2 1 1.26 0.11 1050.00 5.692425 plot(trt,ppmtrans) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : variable lengths differ After my initial post, I found that if I specified the data set in the plot arguments, I could generate a boxplot. I then performed ANOVA on the response after creating factor levels for trt, and generated a stripchart showing the data in each of the three trts. But for future reference, if I need to do linear regression with a similar data set, I'd like to know what is happening. Seems like you still haven't told all that you did. What is ppm.male.mark? Is it an exact copy of `persist', or some subset? Did you do any subsetting after you create persiste.male? If you get that error with plot(trt, ppmtrans), but not with plot(trt, ppmtrans, data=whatever), then the first version is probably getting `trt' and `ppmtrans' that you have lying around the global environment, which are probably results from different subsetting operations (and thus having different lengths). Without more info, we can only guess. One thing to keep in mind: When using the formula interface, it will save you some hair if all the variables used in the formula are in the data frame supplied (and try to always supply the data frame). Andy Thank you-- NH Ellis [[alternative HTML version deleted]] __ R-help@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 __ R-help@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
RE: [R] data.frame error message
Hi Nic Be careful with variables with same names in your environment as variables in data.frame. If you have a variable with the same name e.g. ppmtrans in data frame and in environment, your commands use variable from environment. So probably trt is from data frame and ppmtrans from environment. See what ls() will show you. In models you can specify data=your.data.frame argument and all variables in formula are preferably used from this data frame, if I am not mistaken. Cheers Petr On 23 Feb 2005 at 5:42, Nic Ellis wrote: At 09:47 PM 2/22/2005 -0500, Liaw, Andy wrote: Following the suggestions in the Posting Guide would help us to help you much better. What command(s) did you use to get the data into R? read.table(C:/.../persist.dat,col.names=c(a,b,etc.)) What does the `.dat' file look like? Itn was created in Word, as a plain text file. 6000 24 female 0.0014 1.4 1 3.47 0.25 2478.57 6000 168 female 0.0014 1.4 1 0.73 0.05 521.43 6000 96 female 0.0014 1.4 1 0.96 0.07 685.71 6000 168 female 0.0014 1.4 1 1.36 0.10 971.43 6000 24 female 0.0014 1.4 1 2.69 0.19 1921.43 6000 96 female 0.0014 1.4 1 0.76 0.05 542.86... What are `x' and `y'? 'x' is trt and 'y' is ppmtrans. I did subset commands to find all the males with ppmsamp above a certain value. persist[1:5,] dose trtsex massg massmg vol ppm perc ppmsamp 1 6000 24 female 0.00141.4 1 3.47 0.25 2478.57 2 6000 168 female 0.00141.4 1 0.73 0.05 521.43 3 6000 96female 0.00141.4 1 0.96 0.07 685.71 4 6000 168 female 0.00141.4 1 1.36 0.10 971.43 5 6000 24female 0.00141.4 12.69 0.19 1921.43 ...subsetting commands... ppmtrans-sqrt(sqrt(ppm.male.mark$ppmsamp)) persist.male-cbind(ppm.male.mark,ppmtrans) persist.male[1:5,] dose trt sex massg massmg vol ppm perc ppmsamp ppmtrans 27 6000 96 male 0.00121.2 1 1.82 0.15 1516.67 6.240549 55 6000 168 male 0.00121.2 1 0.90 0.08 750.00 5.233176 70 6000 168 male 0.00121.2 1 1.97 0.16 1641.67 6.365338 76 6000 96 male 0.00121.2 1 4.02 0.34 3350.00 7.607837 83 6000 168 male 0.00121.2 1 1.26 0.11 1050.00 5.692425 plot(trt,ppmtrans) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : variable lengths differ After my initial post, I found that if I specified the data set in the plot arguments, I could generate a boxplot. I then performed ANOVA on the response after creating factor levels for trt, and generated a stripchart showing the data in each of the three trts. But for future reference, if I need to do linear regression with a similar data set, I'd like to know what is happening. Thank you-- NH Ellis [[alternative HTML version deleted]] __ R-help@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 Petr Pikal [EMAIL PROTECTED] __ R-help@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
[R] data.frame error message
Dear R users, I am using v2.0.1 on Windows 2000. I have read a .dat file with several vectors, including 2 factors (2 levels x 3 levels), and a vector of responses, into R. There are no unique row names. When I try plot(x,y) or lm(y~x) the following error is returned: Error in model.frame(formula, rownames,...extranames: variable lengths differ What am I doing wrong? I am a new R user, and I didn't figure it out from the sections on data.frames in Dalgaard, Venable/Ripley, or simpleR, or the help threads. Thanks- Nic Ellis Penn State __ R-help@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
RE: [R] data.frame error message
Following the suggestions in the Posting Guide would help us to help you much better. What command(s) did you use to get the data into R? What does the `.dat' file look like? What are `x' and `y'? Data frames in R, by definition, has to have (unique) rownames. If they are not present in the data source (e.g., a file), they will be created for the data frame, and defaults to 1 through n where n is the number of rows. Andy From: Nic Ellis Dear R users, I am using v2.0.1 on Windows 2000. I have read a .dat file with several vectors, including 2 factors (2 levels x 3 levels), and a vector of responses, into R. There are no unique row names. When I try plot(x,y) or lm(y~x) the following error is returned: Error in model.frame(formula, rownames,...extranames: variable lengths differ What am I doing wrong? I am a new R user, and I didn't figure it out from the sections on data.frames in Dalgaard, Venable/Ripley, or simpleR, or the help threads. Thanks- Nic Ellis Penn State __ R-help@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 __ R-help@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
RE: [R] data.frame into list by columns; merge and row.names
thanks to Andy Liaw and james holtman that replied to my posting this is very basic stuff, but for people strugling with these concepts - as I am... - here goes a more detailed explanation # what I wanted was to create a list where every element would be a column of a given data.frame the only small problem is that I cannot find a way to keep the column names - third paragraph of 3) 1) x - data.frame(a=sample(10), b=rep('a',10), c=sample(10)) xlistBycol - as.list(x) a data.frame is a list in which each column is a vector. you can separate every vector/column of a database into elements of a list by using as.list note that every element is a vector of the same type as in the data.frame element 1 in xlistBycol is an integer, element 2 is a factor with 1 level ('a') 2) x - data.frame(a=sample(10), b=rep('a',10), c=sample(10)) xlistBycol - lapply(x, as.data.frame) the same concept as 1), but this time to each element/column of the data.frame, as.data.frame is applied ther result of this call is a list in which every element is a data.frame with 1 column if you want to keep the row.names you have to give row.names as an argument to as.data.frame: xlistBycol - lapply(x, as.data.frame, row.names(x)) Unfortunately so far I couldn't find an easy way to keep the column names of the data.frame in the corresponding elements of the list 3) to better understand 2) it was useful for me to do this: x - data.frame(a=sample(10), b=sample(10)) xAddOne - lapply(x, function(x) x - x+1) in this case lapply adds 1 to every element of the list/data.frame x and the result is the list xAddOne where every element is the corresponding element of x plus one I hope this doesn't confuse people even more... From: Tiago R Magalhaes Hi a) I want to make a list out of a data.frame, where each element of the list is a column of the data.frame. I looked in the archives and saw a lot of postings but surprsingly none elucidated me. I also tried the split, aggregate help files and counldn't see any easy way to do this. I wouldn't be surprised if it's there, but I really didn't see it. I solved the problem using a very convoluted way: x - data.frame(a=sample(10), b=sample(10), c=sample(10)) f - factor(names(x), levels=names(x)) xx - data.frame(f=f, t(x)) xlist.transpose - split(xx, xx$f) xlist - lapply(xlist, function(x) x=t(x)) I am very convinced there's a much easier way, so if any of you people enlighten me I would appreciate 1. Please make sure the code you show actually works. The last line doesn't. 2. I'm not sure what you want to do. A data frame is already a list. If you want it to be just a list, just use as.list(x). If you want a list where each component is a data frame with one column, use lapply(x, as.data.frame). Andy __ R-help@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
RE: [R] data.frame into list by columns; merge and row.names
From: Tiago R Magalhaes Hi a) I want to make a list out of a data.frame, where each element of the list is a column of the data.frame. I looked in the archives and saw a lot of postings but surprsingly none elucidated me. I also tried the split, aggregate help files and counldn't see any easy way to do this. I wouldn't be surprised if it's there, but I really didn't see it. I solved the problem using a very convoluted way: x - data.frame(a=sample(10), b=sample(10), c=sample(10)) f - factor(names(x), levels=names(x)) xx - data.frame(f=f, t(x)) xlist.transpose - split(xx, xx$f) xlist - lapply(xlist, function(x) x=t(x)) I am very convinced there's a much easier way, so if any of you people enlighten me I would appreciate 1. Please make sure the code you show actually works. The last line doesn't. 2. I'm not sure what you want to do. A data frame is already a list. If you want it to be just a list, just use as.list(x). If you want a list where each component is a data frame with one column, use lapply(x, as.data.frame). Andy b) In terms of my own personal use, it would be much better that merge when using 'row.names' as the by argument would output a data.frame with the merged row.names and not a column 'Row.names'. Also it would be great if it would be possible to choose wich sorting would be the final one - right now the default is argument y, but sometimes argument x is much more useful Of course these are minor points and can be dealt very easily after calling merge, but here it goes my comment anyway. __ R-help@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 __ R-help@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
Re: [R] data.frame into list by columns; merge and row.names
Tiago R Magalhaes tiago17 at socrates.Berkeley.EDU writes: : : Hi : : a) : I want to make a list out of a data.frame, where each element of the : list is a column of the data.frame. : I looked in the archives and saw a lot of postings but surprsingly : none elucidated me. I also tried the split, aggregate help files and : counldn't see any easy way to do this. I wouldn't be surprised if : it's there, but I really didn't see it. : : I solved the problem using a very convoluted way: : : x - data.frame(a=sample(10), b=sample(10), c=sample(10)) : f - factor(names(x), levels=names(x)) : xx - data.frame(f=f, t(x)) : xlist.transpose - split(xx, xx$f) : xlist - lapply(xlist, function(x) x=t(x)) : : I am very convinced there's a much easier way, so if any of you : people enlighten me I would appreciate A data frame _is_ a list. You could do this: class(x) - list # x is from above but you may not even need to do that and may be able to use x directly depending on what you need to do next. : : b) : In terms of my own personal use, it would be much better that merge : when using 'row.names' as the by argument would output a data.frame : with the merged row.names and not a column 'Row.names'. : : Also it would be great if it would be possible to choose wich sorting : would be the final one - right now the default is argument y, but : sometimes argument x is much more useful : Of course these are minor points and can be dealt very easily after : calling merge, but here it goes my comment anyway. __ R-help@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
[R] data.frame into list by columns; merge and row.names
Hi a) I want to make a list out of a data.frame, where each element of the list is a column of the data.frame. I looked in the archives and saw a lot of postings but surprsingly none elucidated me. I also tried the split, aggregate help files and counldn't see any easy way to do this. I wouldn't be surprised if it's there, but I really didn't see it. I solved the problem using a very convoluted way: x - data.frame(a=sample(10), b=sample(10), c=sample(10)) f - factor(names(x), levels=names(x)) xx - data.frame(f=f, t(x)) xlist.transpose - split(xx, xx$f) xlist - lapply(xlist, function(x) x=t(x)) I am very convinced there's a much easier way, so if any of you people enlighten me I would appreciate b) In terms of my own personal use, it would be much better that merge when using 'row.names' as the by argument would output a data.frame with the merged row.names and not a column 'Row.names'. Also it would be great if it would be possible to choose wich sorting would be the final one - right now the default is argument y, but sometimes argument x is much more useful Of course these are minor points and can be dealt very easily after calling merge, but here it goes my comment anyway. __ R-help@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
Re: [R] data.frame into vector
Hi, as other already pointed out as.matrix is what you need. Just one comment: as.matrix(x[1,]) should be much faster for larger data frames compared to as.matrix(x)[1,] Best jan On Tue, 23 Nov 2004, Tiago R Magalhaes wrote: Hi I want to extract a row from a data.frame but I want that object to be a vector . After trying some different ways I end up always with a data.frame or with the wrong vector. Any pointers? x - data.frame(a = factor(c('a',2,'b')), b = c(4,5,6)) I want to get a 4 I tried: as.vector(x[1,]) a b 1 a 4 (resulting in a data.frame even after in my mind having coerced it into a vector!) as.vector(c[1,], numeric='character') [1] 2 4 (almost what I want, except that 2 instead of a - I guess this as to do with levels and factors) Thanks for any help R.Version() $platform [1] powerpc-apple-darwin6.8 $arch [1] powerpc $os [1] darwin6.8 $system [1] powerpc, darwin6.8 $status [1] $major [1] 2 $minor [1] 0.1 $year [1] 2004 $month [1] 11 $day [1] 15 $language [1] R __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- +- Jan Goebel j g o e b e l @ d i w . d e DIW Berlin German Socio-Economic Panel Study (GSOEP) Königin-Luise-Str. 5 D-14195 Berlin -- Germany -- phone: 49 30 89789-377 +- __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] data.frame into vector
Hi I want to extract a row from a data.frame but I want that object to be a vector . After trying some different ways I end up always with a data.frame or with the wrong vector. Any pointers? x - data.frame(a = factor(c('a',2,'b')), b = c(4,5,6)) I want to get a 4 I tried: as.vector(x[1,]) a b 1 a 4 (resulting in a data.frame even after in my mind having coerced it into a vector!) as.vector(c[1,], numeric='character') [1] 2 4 (almost what I want, except that 2 instead of a - I guess this as to do with levels and factors) Thanks for any help R.Version() $platform [1] powerpc-apple-darwin6.8 $arch [1] powerpc $os [1] darwin6.8 $system [1] powerpc, darwin6.8 $status [1] $major [1] 2 $minor [1] 0.1 $year [1] 2004 $month [1] 11 $day [1] 15 $language [1] R __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data.frame into vector
A data frame is a list, and a list is a vector. Once you understand that, yoy may understand what you are seeing. as.matrix(x)[1,] seems to be one of the easiest ways to get what you want On Tue, 23 Nov 2004, Tiago R Magalhaes wrote: Hi I want to extract a row from a data.frame but I want that object to be a vector . After trying some different ways I end up always with a data.frame or with the wrong vector. Any pointers? x - data.frame(a = factor(c('a',2,'b')), b = c(4,5,6)) I want to get a 4 I tried: as.vector(x[1,]) a b 1 a 4 (resulting in a data.frame even after in my mind having coerced it into a vector!) as.vector(c[1,], numeric='character') Eh? I get an error there. [1] 2 4 (almost what I want, except that 2 instead of a - I guess this as to do with levels and factors) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] data.frame into vector
Is this what you want? as.matrix(x[1,])[1,] a b a 4 HTH, Andy From: Tiago R Magalhaes Hi I want to extract a row from a data.frame but I want that object to be a vector . After trying some different ways I end up always with a data.frame or with the wrong vector. Any pointers? x - data.frame(a = factor(c('a',2,'b')), b = c(4,5,6)) I want to get a 4 I tried: as.vector(x[1,]) a b 1 a 4 (resulting in a data.frame even after in my mind having coerced it into a vector!) as.vector(c[1,], numeric='character') [1] 2 4 (almost what I want, except that 2 instead of a - I guess this as to do with levels and factors) Thanks for any help R.Version() $platform [1] powerpc-apple-darwin6.8 $arch [1] powerpc $os [1] darwin6.8 $system [1] powerpc, darwin6.8 $status [1] $major [1] 2 $minor [1] 0.1 $year [1] 2004 $month [1] 11 $day [1] 15 $language [1] R __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data.frame into vector
On Tue, 2004-11-23 at 16:27 +, Tiago R Magalhaes wrote: Hi I want to extract a row from a data.frame but I want that object to be a vector . After trying some different ways I end up always with a data.frame or with the wrong vector. Any pointers? x - data.frame(a = factor(c('a',2,'b')), b = c(4,5,6)) I want to get a 4 I tried: as.vector(x[1,]) a b 1 a 4 (resulting in a data.frame even after in my mind having coerced it into a vector!) as.vector(c[1,], numeric='character') [1] 2 4 (almost what I want, except that 2 instead of a - I guess this as to do with levels and factors) Thanks for any help Part of the problem that you are having, as you seem to pick up, is that the first column in 'x' is a factor and you need to coerce it to a character. If you review the help for as.matrix, you will note in the details section: as.matrix is a generic function. The method for data frames will convert any non-numeric/complex column into a character vector using format and so return a character matrix, except that all-logical data frames will be coerced to a logical matrix. Thus, one approach is: as.matrix(x)[1, ] a b a 4 This coerces the data frame to a character matrix, which is then subsetted to the first row only. HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data.frame size limit
On Tue, 8 Jun 2004, Philip Sobolik wrote: Is there a limit to the number of columns that a data.frame can have? Yes. A data frame is a list, and a list is limited to 2^31-1 items. For example, can I read.csv() a file that has 1000 columns and 10,000 rows, will it break or is it limited by available memory. It will not `break', but it may fail with an error message, depending how much the `available memory' is. R will run in 16Mb RAM but this problem will not. Both ?read.table and the R Data Import/Export Manual give hints on how to read large tables efficiently, and it may well be necessary to follow them. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] data.frame size limit
Is there a limit to the number of columns that a data.frame can have? For example, can I read.csv() a file that has 1000 columns and 10,000 rows, will it break or is it limited by available memory. ... Philip Sobolik 781-862-8719 x111 Wrightsoft Corporation 781-861-2058 fax 394 Lowell Street, Suite 12 [EMAIL PROTECTED] Lexington, MA 02420 www.wrightsoft.com __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] data.frame preserves names for all columns
Dear R-help, I was surprised to find that data.frame() keeps the names of all columns: x1 - structure(1:5, names=1:5) x2 - structure(5:1, names=5:1) x3 - structure(10:6, names=10:6) x - data.frame(x1, x2, x3) str(x) `data.frame': 5 obs. of 3 variables: $ x1: Named int 1 2 3 4 5 ..- attr(*, names)= chr 1 2 3 4 ... $ x2: Named int 5 4 3 2 1 ..- attr(*, names)= chr 5 4 3 2 ... $ x3: Named int 10 9 8 7 6 ..- attr(*, names)= chr 10 9 8 7 ... I could not find mention of this in ?data.frame. The problem is that when I extract a column of `x', I would be expected the rownames of the data frame to be used as the names (and short of that, no names attribute), rather than the original names. Is this intentional? Best, Andy Andy Liaw, PhD Biometrics Research PO Box 2000, RY33-300 Merck Research Labs Rahway, NJ 07065 mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 732-594-0820 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] data.frame to matrix
Hello all, I've had trouble converting a data.frame to a matrix (numeric) using either data.matrix() and as.matrix(). After executing one of those I end up with another data.frame with only the first column of the original data.frame. I use a window (tcltk) to let the user choose the columns he wants and then I retrieve them using the following: varstemp - .numeric[as.numeric(tkcurselection(subgroupsBox)) + 1] where .numeric is the original (complete) data.frame. Any ideas why is this happening? I'm using R1.8.1 in WinXP by the way. Thanks. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data.frame to matrix
On Mon, 9 Feb 2004 17:47:36 -0300, Gustavo Pinheiro [EMAIL PROTECTED] wrote : Hello all, I've had trouble converting a data.frame to a matrix (numeric) using either data.matrix() and as.matrix(). After executing one of those I end up with another data.frame with only the first column of the original data.frame. I use a window (tcltk) to let the user choose the columns he wants and then I retrieve them using the following: varstemp - .numeric[as.numeric(tkcurselection(subgroupsBox)) + 1] where .numeric is the original (complete) data.frame. Any ideas why is this happening? I'm using R1.8.1 in WinXP by the way. I'd guess as.numeric(tkcurselection(subgroupsBox)) + 1 isn't returning what you think it's returning, or maybe .numeric isn't in the form you think. I'd also recommend using both row and column indices when working with data frames. What you have selects columns from a data.frame, but not from a matrix (assuming that the index is a vector of integers). I find it's safer to treat data.frames as matrices whenever you can, i.e. use a blank row index varstemp - .numeric[ , as.numeric(tkcurselection(subgroupsBox)) + 1] Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RES: [R] data.frame to matrix
Hi Duncan, You were right. It was a vector and not a data.frame that I was dealing with. But still I am having dificulties. Please, take a look at some output (I am using R Commander GUI by the way): R-cmdr print(b) [1] 0.70 0.85 0.80 0.70 0.75 0.75 0.80 0.70 0.80 0.75 0.80 0.79 0.78 0.75 0.76 [16] 0.70 0.70 0.70 0.80 0.80 0.70 0.65 0.60 0.70 0.55 0.80 0.65 0.60 0.70 [1] 0.65 0.75 0.80 0.70 0.65 0.75 0.65 0.80 0.85 0.70 0.80 0.79 0.78 0.85 0.76 [16] 0.75 0.85 0.60 0.80 0.75 0.85 0.85 0.65 0.70 0.65 0.65 0.75 0.60 0.60 [1] 0.65 0.75 0.80 0.70 0.65 0.75 0.65 0.80 0.85 0.70 0.80 0.79 0.78 0.85 0.76 [16] 0.75 0.85 0.60 0.80 0.75 0.85 0.85 0.65 0.70 0.65 0.65 0.75 0.60 0.60 R-cmdr print(length(b)) [1] 29 [1] 29 [1] 29 R-cmdr print(b[1]) [1] 0.70 [1] 0.65 [1] 0.65 R-cmdr print(b[1,]) Error: incorrect number of dimention R-cmdr print(b[,2]) Error: incorrect number of dimention Looking at this output I figured b is a vector of vectors (3 to be exact). The thing is I want to create a matrix made of b's lines (which were originaly columns in my dataset) as columns, but I could not find a way to retrieve a line from b in a way similar to what one would do with dataframes (dataframe[1,]). You can see in the above output that a call to b[1,] returns an error and a call to b[1] returns the first column. So, how to retrieve a whole line? Keep in mind that the size of b is not known before hand, so if it turns out to be necessary to go through each element another problem would arise: a call to length() returns the length of each one of these 3 vectors, but not the length of the containg vector b which is 3. Was I clear enough? My english is not so great ;-) Regards, Gustavo. -Mensagem original- De: Duncan Murdoch [mailto:[EMAIL PROTECTED] Enviada em: Monday, February 09, 2004 5:25 PM Para: Gustavo Pinheiro Cc: [EMAIL PROTECTED] Assunto: Re: [R] data.frame to matrix On Mon, 9 Feb 2004 17:47:36 -0300, Gustavo Pinheiro [EMAIL PROTECTED] wrote : Hello all, I've had trouble converting a data.frame to a matrix (numeric) using either data.matrix() and as.matrix(). After executing one of those I end up with another data.frame with only the first column of the original data.frame. I use a window (tcltk) to let the user choose the columns he wants and then I retrieve them using the following: varstemp - .numeric[as.numeric(tkcurselection(subgroupsBox)) + 1] where .numeric is the original (complete) data.frame. Any ideas why is this happening? I'm using R1.8.1 in WinXP by the way. I'd guess as.numeric(tkcurselection(subgroupsBox)) + 1 isn't returning what you think it's returning, or maybe .numeric isn't in the form you think. I'd also recommend using both row and column indices when working with data frames. What you have selects columns from a data.frame, but not from a matrix (assuming that the index is a vector of integers). I find it's safer to treat data.frames as matrices whenever you can, i.e. use a blank row index varstemp - .numeric[ , as.numeric(tkcurselection(subgroupsBox)) + 1] Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data.frame to matrix
Dear Gustavo, To fill in other list members, this is occurring with code written to augment the Rcmdr package. The problem is that .numeric is a vector of names of numeric variables in the active data set (data frame) maintained by Rcmdr, it is not itself a data frame. Consequently, your varstemp is also a vector of names, which could be used to index the active data set, whose name is stored in .activeDataSet. I hope that this helps, John On Mon, 9 Feb 2004 17:47:36 -0300 Gustavo Pinheiro [EMAIL PROTECTED] wrote: Hello all, I've had trouble converting a data.frame to a matrix (numeric) using either data.matrix() and as.matrix(). After executing one of those I end up with another data.frame with only the first column of the original data.frame. I use a window (tcltk) to let the user choose the columns he wants and then I retrieve them using the following: varstemp - .numeric[as.numeric(tkcurselection(subgroupsBox)) + 1] where .numeric is the original (complete) data.frame. Any ideas why is this happening? I'm using R1.8.1 in WinXP by the way. Thanks. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: RES: [R] data.frame to matrix
On Mon, 9 Feb 2004 19:10:00 -0300, you wrote: Hi Duncan, You were right. It was a vector and not a data.frame that I was dealing with. But still I am having dificulties. Please, take a look at some output (I am using R Commander GUI by the way): R-cmdr print(b) [1] 0.70 0.85 0.80 0.70 0.75 0.75 0.80 0.70 0.80 0.75 0.80 0.79 0.78 0.75 0.76 [16] 0.70 0.70 0.70 0.80 0.80 0.70 0.65 0.60 0.70 0.55 0.80 0.65 0.60 0.70 [1] 0.65 0.75 0.80 0.70 0.65 0.75 0.65 0.80 0.85 0.70 0.80 0.79 0.78 0.85 0.76 [16] 0.75 0.85 0.60 0.80 0.75 0.85 0.85 0.65 0.70 0.65 0.65 0.75 0.60 0.60 [1] 0.65 0.75 0.80 0.70 0.65 0.75 0.65 0.80 0.85 0.70 0.80 0.79 0.78 0.85 0.76 [16] 0.75 0.85 0.60 0.80 0.75 0.85 0.85 0.65 0.70 0.65 0.65 0.75 0.60 0.60 That's a strange looking display -- b is probably some sort of object with a special print method. You can figure out what it is using str(b). Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] data.frame subset?
Can someone tell me why this is since I can't seem to find an explination in the docs or FAQ for this. Since there are no BM in the mtrs data.frame, but only in the parent data.frame (trees), I'm assuming the subset data.frame is still associated with the original. Is that correct and how would I create a completly separate data.frame since I'll be using by, lapply and such on the subset data.frame using sp which currently causes by to choke... mtrs - trees[trees$m == 1,] mtrs plot tree sp m dbh tht bfvol cfvol 1 11 DF 1 44 185 3825.79 622.97 2 12 DF 1 38 188 3166.69 504.12 26 31 DF 1 42 185 3568.80 578.09 51 54 DF 1 30 189 2071.36 348.28 67 71 DF 1 33 168 2036.30 342.90 70 74 DF 1 45 180 3665.82 621.90 71 75 DF 1 30 160 1530.88 274.69 81 91 DF 1 44 175 3398.52 576.79 82 92 DF 1 68 205 9516.82 1461.21 95111 DF 1 30 170 1775.60 299.54 96112 DF 1 44 197 4249.98 680.64 97113 DF 1 44 187 3914.88 632.42 107 11 13 WH 1 44 175 3398.52 576.79 121 132 WF 1 48 205 5241.14 827.57 126 137 DF 1 40 182 3188.77 522.43 138 152 DF 1 69 182 7852.22 1285.42 143 157 DF 1 28 142 1146.77 207.67 159 179 DF 1 12 88 99.13 25.43 177 197 DF 1 37 162 2309.06 391.48 attributes( mtrs$sp ) $class [1] factor $levels [1] BM DF WF WH --- Jeff D. Hamann Forest Informatics, Inc. PO Box 1421 Corvallis, Oregon USA 97339-1421 (office) 541-754-1428 (cell) 541-740-5988 [EMAIL PROTECTED] www.forestinformatics.com __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] data.frame subset?
On Tue, 18 Nov 2003, Jeff D. Hamann wrote: Can someone tell me why this is since I can't seem to find an explination in the docs or FAQ for this. Since there are no BM in the mtrs data.frame, but only in the parent data.frame (trees), I'm assuming the subset data.frame is still associated with the original. Is that correct and how would I create a completly separate data.frame since I'll be using by, lapply and such on the subset data.frame using sp which currently causes by to choke... mtrs - trees[trees$m == 1,] mtrs plot tree sp m dbh tht bfvol cfvol 1 11 DF 1 44 185 3825.79 622.97 2 12 DF 1 38 188 3166.69 504.12 26 31 DF 1 42 185 3568.80 578.09 51 54 DF 1 30 189 2071.36 348.28 67 71 DF 1 33 168 2036.30 342.90 70 74 DF 1 45 180 3665.82 621.90 71 75 DF 1 30 160 1530.88 274.69 81 91 DF 1 44 175 3398.52 576.79 82 92 DF 1 68 205 9516.82 1461.21 95111 DF 1 30 170 1775.60 299.54 96112 DF 1 44 197 4249.98 680.64 97113 DF 1 44 187 3914.88 632.42 107 11 13 WH 1 44 175 3398.52 576.79 121 132 WF 1 48 205 5241.14 827.57 126 137 DF 1 40 182 3188.77 522.43 138 152 DF 1 69 182 7852.22 1285.42 143 157 DF 1 28 142 1146.77 207.67 159 179 DF 1 12 88 99.13 25.43 177 197 DF 1 37 162 2309.06 391.48 attributes( mtrs$sp ) $class [1] factor $levels [1] BM DF WF WH A factor remembers all its levels unless you tell to drop them as in: mtrs - trees[trees$m == 1, , drop = TRUE] Uwe Ligges __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] data.frame subsetting
Hi, I think I have the same problem. The following works aa-data.frame(1:10) ab-data.frame(1:12) ba-data.frame(1:14) bb-data.frame(1:16) xa-data.frame() xa$aa-aa xa$ab-ab xb-data.frame() xb$ba-ba xb$bb-bb xx-data.frame() xx$xa-xa xx$xb-xb summary(xx) xa.aa.X1.10 xa.ab.X1.12 xb.ba.X1.14 xb.bb.X1.16 Min. : 1.00Min. : 1.00 Min. : 1.00Min. : 1.00 1st Qu.: 3.251st Qu.: 3.75 1st Qu.: 4.251st Qu.: 4.75 Median : 5.50Median : 6.50 Median : 7.50Median : 8.50 Mean : 5.50Mean : 6.50 Mean : 7.50Mean : 8.50 3rd Qu.: 7.753rd Qu.: 9.25 3rd Qu.:10.753rd Qu.:12.25 Max. :10.00Max. :12.00 Max. :14.00Max. :16.00 is.data.frame(xx) [1] TRUE is.data.frame(xx$xa) [1] TRUE is.data.frame(xx$xb) [1] TRUE is.data.frame(xx$xa$aa) [1] TRUE this works not: ya-data.frame() ya[[aa]]-aa Error in [[-.data.frame(*tmp*, aa, value = aa) : replacement has 10 rows, data has 0 So I also would like produce a sub-data.frame, maybe by this way subframename-subset 1 mydataframe[[subframename]] - mysubframe1 subframename-subset 2 mydataframe[[subframename]] - mysubframe2 ... is this possible?? Normally I would like to use a loop to do this!! __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] data.frame - matrix
Dear colleagues, I am beginner, so the primitive questions: in pls.pcr package in the function mvr I need to indicate a matrix of observations and a vector of responses. But read.table function returns the data.frame object. What is the way for conversion of the data.frame object into matrix and vector objects? And what is the way for writing the results down into file? Thank you very much. Sokratis. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] data.frame - matrix
One place to start is A Guide for the Unwilling S User. Patrick Burns Burns Statistics [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Sokratis Alikhanidi wrote: Dear colleagues, I am beginner, so the primitive questions: in pls.pcr package in the function mvr I need to indicate a matrix of observations and a vector of responses. But read.table function returns the data.frame object. What is the way for conversion of the data.frame object into matrix and vector objects? And what is the way for writing the results down into file? Thank you very much. Sokratis. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] data.frame - matrix
I think data.matrix() is what you want. -roger Sokratis Alikhanidi wrote: Dear colleagues, I am beginner, so the primitive questions: in pls.pcr package in the function mvr I need to indicate a matrix of observations and a vector of responses. But read.table function returns the data.frame object. What is the way for conversion of the data.frame object into matrix and vector objects? And what is the way for writing the results down into file? Thank you very much. Sokratis. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] data.frame with duplicated id's
Hi, is there a exstisting function (..i found nothing until now.) what makes it possible transfrom a dataset: ID AGE V.MAI V.JUNE 11 20 100 120 12 30 200 90 into IDAGEV 1120 100 1120 120 1230200 123090 ,or have i to programm ths my self? Thanks for any comment, help and/or starting point. regards,christian [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] data.frame with duplicated id's
Try ?reshape A -Original Message- From: Christian Schulz [mailto:[EMAIL PROTECTED] Sent: Wednesday, 24 September 2003 3:42 PM To: [EMAIL PROTECTED] Subject: [R] data.frame with duplicated id's Hi, is there a exstisting function (..i found nothing until now.) what makes it possible transfrom a dataset: ID AGE V.MAI V.JUNE 11 20 100 120 12 30 200 90 into IDAGEV 1120 100 1120 120 1230200 123090 ,or have i to programm ths my self? Thanks for any comment, help and/or starting point. regards,christian [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] data.frame subsetting
Hi, is there advice how to subset a data.frame, where until R version 1.7.0 it was possible to write data[[subset]] which meant the same as data$subset (data is a data.frame). From 1.7.1 on this does not seem to work longer. Could there be a bug in downwards compatibility? sincerely yours Dirk __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] data.frame subsetting
Dirk Repsilber wrote: Hi, is there advice how to subset a data.frame, where until R version 1.7.0 it was possible to write data[[subset]] which meant the same as data$subset (data is a data.frame). From 1.7.1 on this does not seem to work longer. Could there be a bug in downwards compatibility? sincerely yours Works for me. Are you sure the object data is a data.frame in your case? Uwe Ligges __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] data.frame subsetting
On Thu, 24 Jul 2003 16:27:28 +0200, Dirk Repsilber [EMAIL PROTECTED] wrote : Hi, is there advice how to subset a data.frame, where until R version 1.7.0 it was possible to write data[[subset]] which meant the same as data$subset (data is a data.frame). From 1.7.1 on this does not seem to work longer. Could there be a bug in downwards compatibility? What are you trying to achieve? The notation you give still works if subset is one of the column names; I don't think it ever worked if subset was a logical vector, like its name would suggest. Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] data.frame subsetting
Still works for me in both 1.7.1 and 1.8.0 (in development) data(women) women[[height]] [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 women$height [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 Can you provide an example of how it is failing for you? Dirk Repsilber [EMAIL PROTECTED] writes: Hi, is there advice how to subset a data.frame, where until R version 1.7.0 it was possible to write data[[subset]] which meant the same as data$subset (data is a data.frame). From 1.7.1 on this does not seem to work longer. Could there be a bug in downwards compatibility? sincerely yours Dirk __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help -- Douglas Bates[EMAIL PROTECTED] Statistics Department608/262-2598 University of Wisconsin - Madisonhttp://www.stat.wisc.edu/~bates/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help