similar to: Converting a Vector into a 2-level Factor

Displaying 20 results from an estimated 30000 matches similar to: "Converting a Vector into a 2-level Factor"

2007 Nov 28
1
ifelse function
Hi there, I need help with IFELSE function. The column g of my dataset pth, pth$g consists of "aa", "ao", "dcl", "iy", "sh". The last few values of pth$g looks like: [4496] sh ao ao sh iy dcl dcl aa iy iy aa sh ao ao Levels: aa ao dcl iy sh I want to convert these values into 1,2,3,4,5. I tried to use a loop and I found the following
2010 Jul 29
1
Displaying Counts of Unused Factors in Contingency Tables with table()
R-philes, I have a question about displaying counts of unused factors using the table() function. I have two vectors with character data in them: local.labels("ah", "ah", "ah~") local.preds("ah", "ah", "ah") If I use the table function as shown below, I get an error because the number of levels do not match up. v.cont.table <-
2009 Dec 09
1
Exporting Contingency Tables with xtable
Dear R-philes: I am having an issue with exporting contingency tables with xtable(). I set up a contingency and convert it to a matrix for passing to xtable() as shown below. v.cont.table <- table(v_lda$class, grps, dnn=c("predicted", "observed")) v.cont.mat <- as.matrix(v.cont.table) Both produce output as follows: observed predicted uh uh~ uh 201
2005 Jul 08
2
removing factor level represented by less than x rows
In a number of different situations I'm trying to remove factor levels that are represented by less than a certain number of rows, e.g. if I had the dataset aa below and wanted to remove the species that are represented in less than 2 rows: data(iris) aa <- iris[1:101,] In this case, since I can see that the species virginica only has one row, I can write: table(aa$Species) setosa
2012 Mar 03
3
Using ddply within a function by argument transfer
An embedded and charset-unspecified text was scrubbed... Name: inte tillg?nglig URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120303/a62e41f2/attachment.pl>
2008 Feb 03
4
Extract vowels and consonants using Ruby Regex
Hello, I am trying to build a regex to extract vowels and consonants from a string. So far, I am able to extract the basic a-e-i-o-u sequence using the following extension to the String class: class String def vowels scan(/[aeiou]/i) end def consonants scan(/[^aeiou]/i) end end examples: >> "Mary had a little lamb".vowels => aaaiea >> "Mary had a
2011 Jun 09
2
Coercing Output from mget() into Proper Data Frame
Hello R-philes: I have the following function that gets the output of mget() and converts it to a data frame to return. What I am finding is that the dimensions are wrong. Basically, I get: bridesmaid wed u see m gt lt like love X.0 dress pagetrack one go X3 get 1 56 35 27 30 24 20 20 23 28 17 25 16 16 28 15 26 Instead, I want something like: [1] bridesmaid
2009 Aug 12
1
inserting into data frame gives "invalid factor level, NAs generated"
I am calculating some values that I am inserting into a data frame. From what I have read, creating the dataframe ahead of time is more efficient, since rbind (so far the only solution I have found to appending to a data frame) is not very fast. What I am doing is the following: # create data frame goframe = data.frame(goA = character(10), goB = character(10), value = numeric(10)) goframe[1,] =
2001 Sep 24
1
need help creating means table
Hello, I have been trying to use by to create a means table, but receive the error " by(xx, list(subjs, cons, vowels), mean) Error in Summary.data.frame(..., na.rm = na.rm) : only defined on a data frame with all numeric or complex variables" when the data frame consists of three factor columns (subjs, cons and vowels) and 5 numeric data columns. The output I'm looking for is a
2024 Mar 01
1
gsub issue with consecutive pattern finds
Here's another *incorrect* way to do it -- incorrect because it will not always work, unlike Iris's correct solution. But it does not require PERL type matching. The idea: separate the two vowels in the regex by a character that you know cannot appear (if there is such) and match it optionally, e.g. with '*" repetition specifier. I used "?" for the optional character
2008 Apr 15
2
a question of alphabetical order
Hi all, In Spanish vowels with accent like ?, ?, ... doesn't affect to the alphabetical order of vector of strings. I mean, a or ? don't matter for establishing the alphabetical order. Nevertheless, while working with R order, here is what I get. Given a file transport.txt medio#variable avi?n#34 barco#33 bicicleta#3 ?ngulo#37 cami?n#54 coche#23 tren#67 > toPlot <-
2017 Jul 07
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote: > > This is not serious problem but I just wonder if someone can explain what is happening. > The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask.
2012 Mar 21
2
Best way to compute the difference between two levels of a factor ?
Dear R-help Members, I am wondering if anyone think of the optimal way of computing for several numeric variable the difference between 2 levels of a factor. To be clear let's generate a simple data frame with 2 numeric variables collected for different subjects (ID) and 2 levels of a TIME factor (time of evaluation)
2024 Mar 01
1
gsub issue with consecutive pattern finds
Hi Iris, Thank you. Further, very nice solution. Best, Iago On 01/03/2024 12:49, Iris Simmons wrote: > Hi Iago, > > > This is not a bug. It is expected. Patterns may not overlap. However, there > is a way to get the result you want using perl: > > ```R > gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) > ``` >
2008 Feb 20
2
spelling with <g>?
Hello, What should the following input produce? Dutch has shifted Germanic g to the velar fricatives [?] and [x], but retained the spelling with <g> and thus at least a visual similarity to German; English and Frisian have shifted g to [j] before palatal vowels The Dingus says: <p>Dutch has shifted Germanic g to the velar fricatives [?] and [x], but retained the spelling
2024 Mar 01
1
gsub issue with consecutive pattern finds
Hi all, I tested next command: gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue") with the following output: [1] "a_eri_ou_e" So, there are two consecutive vowels where an underscore is not added. May it be a bug? Is it expected (bug or not)? Is there any chance to get what I want (an underscore between each pair of consecutive vowels)?
2017 Jul 07
2
Factor vs character in a data.frame vs vector
This is not? serious problem but I just wonder if someone can explain what is happening. The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. Thanks #================================================ dat1 <- data.frame(aa = letters[1:10]) str(dat1)
2017 Jul 08
2
Factor vs character in a data.frame vs vector
Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <marc_schwartz at me.com> wrote: > On Jul 7, 2017, at 6:03
2009 Jun 20
1
how to apply the dummy coding rule in a dataframe with complete factor levels to another dataframe with incomplete factor levels?
Dear R helpers: Sorry to bother for a basic question about model.matrix. Basically, I want to apply the dummy coding rule in a dataframe with complete factor levels to another dataframe with incomplete factor levels. I used model.matrix, but could not get what I want. The following is an example. #Suppose I have two dataframe A and B
2024 Mar 01
1
gsub issue with consecutive pattern finds
Hi Iago, This is not a bug. It is expected. Patterns may not overlap. However, there is a way to get the result you want using perl: ```R gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) ``` The specific change I made is called a positive lookahead, you can read more about it here: https://www.regular-expressions.info/lookaround.html