An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120501/51fe59bd/attachment.pl>
Question about expand.grid function in R
9 messages · Peter Dalgaard, Kelly Cool, R. Michael Weylandt +3 more
I don't think you can do it within expand.grid() but something like this might work: rownames(x) <- apply(x, 1, paste, collapse = "") Michael
On Tue, May 1, 2012 at 5:05 AM, Kelly Cool <kellycool79 at yahoo.com> wrote:
Hi,
I am extremely new to R, and was wondering if someone would be able to help me with a question regarding the expand.grid function. When I input
expand.grid.rep <- function(x, n=1) do.call(expand.grid, rep(list(x),n))
expand.grid.rep(c("a", "b", "c"), 3)
my output is as follows,
Var1 Var2 Var3
1 ? ? a ? ?a ? ?a
2 ? ? b ? ?a ? ?a
3 ? ? c ? ?a ? ?a
4 ? ? a ? ?b ? ?a
5 ? ? b ? ?b ? ?a
6 ? ? c ? ?b ? ?a
7 ? ? a ? ?c ? ?a
8 ? ? b ? ?c ? ?a
9 ? ? c ? ?c ? ?a
10 ? ?a ? ?a ? ?b
11 ? ?b ? ?a ? ?b
12 ? ?c ? ?a ? ?b
13 ? ?a ? ?b ? ?b
14 ? ?b ? ?b ? ?b
15 ? ?c ? ?b ? ?b
16 ? ?a ? ?c ? ?b
17 ? ?b ? ?c ? ?b
18 ? ?c ? ?c ? ?b
19 ? ?a ? ?a ? ?c
20 ? ?b ? ?a ? ?c
21 ? ?c ? ?a ? ?c
22 ? ?a ? ?b ? ?c
23 ? ?b ? ?b ? ?c
24 ? ?c ? ?b ? ?c
25 ? ?a ? ?c ? ?c
26 ? ?b ? ?c ? ?c
27 ? ?c ? ?c ? ?c
I was wondering if there was anyway I can change the row numbers to labels that indicate what is in each row. Instead of a 1, I'd like to have a label saying "aaa", etc. I'm not sure if this is even possible within the expand.grid function but any help would be appreciated. Thanks.
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
On May 1, 2012, at 15:36 , R. Michael Weylandt wrote:
I don't think you can do it within expand.grid() but something like this might work: rownames(x) <- apply(x, 1, paste, collapse = "")
Also rownames(x) <- do.call(paste, c(x, sep="")) or, in recent versions, rownames(x) <- do.call(paste0, x)
Michael On Tue, May 1, 2012 at 5:05 AM, Kelly Cool <kellycool79 at yahoo.com> wrote:
Hi,
I am extremely new to R, and was wondering if someone would be able to help me with a question regarding the expand.grid function. When I input
expand.grid.rep <- function(x, n=1) do.call(expand.grid, rep(list(x),n))
expand.grid.rep(c("a", "b", "c"), 3)
my output is as follows,
Var1 Var2 Var3
1 a a a
2 b a a
3 c a a
4 a b a
5 b b a
6 c b a
7 a c a
8 b c a
9 c c a
10 a a b
11 b a b
12 c a b
13 a b b
14 b b b
15 c b b
16 a c b
17 b c b
18 c c b
19 a a c
20 b a c
21 c a c
22 a b c
23 b b c
24 c b c
25 a c c
26 b c c
27 c c c
I was wondering if there was anyway I can change the row numbers to labels that indicate what is in each row. Instead of a 1, I'd like to have a label saying "aaa", etc. I'm not sure if this is even possible within the expand.grid function but any help would be appreciated. Thanks.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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 at r-project.org 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.
Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
27 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120528/baccacb9/attachment.pl>
On Mon, May 28, 2012 at 3:16 PM, Kelly Cool <kellycool79 at yahoo.com> wrote:
I was wondering if there was a quick way to extract out certain rows from a data set in R? I have a data.frame, LOG, ?where in one column, sample_data_tx, there is a list of 62 different types of treatment. I've sub-selected the rows that contain the names, "PLO" and "NOY" to make a new vector which I call, Test. ?Here's my code so far, ##In LOG data set, Test set is every treatment, PLO and NOY## ##Select rows in the LOG data set that contain Noy## Noy <- which(LOG$sample_data_tx == "Noy") ##Select rows in the LOG data set that contain PLO## PLO <- which(LOG$sample_data_tx == "PLO") ##Make Test Set## ?Test <- c(Noy, PLO)
Test
[1] ?8 24 50 23 29 46 55 Within the data.frame, LOG, I would like to now make another vector, "Training", that contains every row in the column, "sample_data_tx", except rows 8, 24, 50, 23, 29, 46, 55.
I think you're looking for negative indexing (which is, in my opinion,
pretty much the best thing ever)
E.g.,
x <- letters[1:10]
x[1:3] # First three letters
x[-(1:3)] # Without the first three letters
x[-4] # Leave out "d"
etc.
Of course, for this case, you might also want the subset function:
subset(LOG, sample_data_tx %in% c("Noy","PLO"))
"Test" is also an integer and I am hoping to make a hierarchical plot with both the "Test" and "Training" vectors so I am not sure if I first need to convert the data from integer to numeric form?
No, almost always these sorts of conversions will be taken care of you automatically Best, Michael
I am new to R so all help is appreciated. Thanks in advance. ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120528/02427142/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120529/f1cf0920/attachment.pl>
This is a well-known limitation. You have to group categorical attributes together to work around. -------------------------------------------------------------------------------------- Weifeng (aaron) liu ?|??retail systems pricing? | ?sr research scientist -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Kelly Cool Sent: Tuesday, May 29, 2012 7:47 AM To: r-help at r-project.org Subject: [R] Question about random Forest function in R Hello,? I am trying to run the random Forest function on a data.frame using the following code.. myrf <- randomForest (y=sample_data_metal, x=Train, importance=TRUE, proximity=TRUE) However, an error occurs saying, "can not handle categorical predictors with more than 32 categories".? My "x=Train" data.frame is quite large and my "y=sample_data_metal" is one column.? I'm not sure how to go about fixing this error or if there is even a way to get around this error. Thanks in advance for any help.?
Hi Kelly,
The function has a limitation that it cannot handle any column in your "x" that is a categorical variable with more than 32 categories. One possibility is to see if you can "bin" some of the categories into one to get below 32 categories.
Andy
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Kelly Cool
Sent: Tuesday, May 29, 2012 10:47 AM
To: r-help at r-project.org
Subject: [R] Question about random Forest function in R
Hello,?
I am trying to run the random Forest function on a data.frame using the following code..
myrf <- randomForest (y=sample_data_metal, x=Train, importance=TRUE, proximity=TRUE)
However, an error occurs saying, "can not handle categorical predictors with more than 32 categories".?
My "x=Train" data.frame is quite large and my "y=sample_data_metal" is one column.?
I'm not sure how to go about fixing this error or if there is even a way to get around this error. Thanks in advance for any help.?
Notice: This e-mail message, together with any attachme...{{dropped:11}}