Questions tagged [r-factor]

The factor is a data type in the R language, used to encode categorical or enumerated data.

The factor is a data type in the R language, used to encode categorical or enumerated data. This data type is often used in statistical models.

This type is encoded as an integer value, along with a lookup table of factor levels. The factor levels are represented as a vector of character strings. This representation allows easy conversion to character, and efficient use in statistical computations.

437 questions
-1
votes
2 answers

BASIC - R Data type issue; type integer and contains many 'levels'?

I am new to the beautiful language of R and currently I am having difficulties understanding the following: I am loading in a CSV file. This CSV file contains two columns. The first column is a unique ID. The second column is named 'content'. The…
nielsvg
  • 25
  • 5
-1
votes
1 answer

R: GLM: factor level not present in data set, but I still want coefficient

When I train a model, and afterwards predict on testing data, sometimes some factor level that is not present in the training data shows up in the testing data, and it gives me an error, because the factor level was not available when training the…
Helen
  • 331
  • 9
  • 28
-1
votes
1 answer

R randomForest too many categories error even with fewer than 53 categories

I'm trying to make a random forest with the following movies.rf <- randomForest(Infl.Adj.Dom.BoxOffice~. -Genre -Source -ProductionMethod -CreativeType, data=Movies, subset=train) I get Error in randomForest.default(m, y, ...) : Can not handle…
Person
  • 1
  • 1
-1
votes
1 answer

mis-matched output from unique() and nlevels()

In an attempt to run an lm(), R returned an error from having factors with less than 2-levels. Below is a short table that lists the Type, and 3-measures of 'levels'. Why would length(unique(x[,i])) not provide the same output as nlevels(x[,i])?
braxtonlewis
  • 41
  • 1
  • 8
-1
votes
1 answer

h2o (un) ordered factor

Hi I have a problem with the h2o(3) not loading my factors. The Problem is similar to: Unable to convert data frame to h2o object However I tried to use: myData<- data.frame(apply(myData, 2, factor, ordered=FALSE)) but the error persists: Provided…
Georg Heiler
  • 13,862
  • 21
  • 115
  • 217
-1
votes
2 answers

Levels in R with conditions on time

I have a dataset with date and time variables. I created a new variable (mutated from time) and called it "time.of.day". I would like to assign different labels (4 actually) conditioned by the time period. I was trying the…
user10853
  • 266
  • 1
  • 3
  • 17
-1
votes
1 answer

Printing more than 3 factors in r table

I have 2 factor variables and 1 Logical variable in my R dataframe : > table(eaos$GM, eaos$CONTRACTOR.FLAG) N Y Belfast 1145 0 East Anglia 7969 207 London …
Shery
  • 1,459
  • 2
  • 18
  • 40
-1
votes
1 answer

How to make a factor a numeric value?

This is my second time posting, so I hope I get the "reproducible example" thing right. Here is the error, Error in if ((sound[i, 3] < -10 & sound[min(81, i + 1), 3] > -10) | (sound[i, : missing value where TRUE/FALSE needed In addition: Warning…
Dent
  • 3
  • 3
-1
votes
1 answer

Convert a factor to column to numeric R

I bring in a data set using the following command: rbc <- read.csv("rbc hgb.csv", header = T) data <- rbc[rbc$Result_Value_After != "NULL",] For some reason the rbc$Result_Value_After gets treated like a factor, so I issue the following…
MCP_infiltrator
  • 3,053
  • 10
  • 39
  • 72
-1
votes
1 answer

how to tell big.matrix to treat certain columns as vectors

I have a big data set that includes character variables of many different values. I'm trying to read the data as big.matrix and then use biglm.big.matrix to build linear models. However, since big.matrix will convert all character vectors to…
user1030532
  • 561
  • 1
  • 5
  • 11
-2
votes
1 answer

How to show all the values in each level in r?

I have a data-set that looks like this : first <- c(5:14) second <- rep(c("a","b"),5) c <- cbind(first, second) c first second [1,] "5" "a" [2,] "6" "b" [3,] "7" "a" [4,] "8" "b" [5,] "9" "a" [6,] "10" "b" [7,] "11" "a" [8,] "12"…
kim1298
  • 21
  • 2
  • 9
-2
votes
1 answer

R data frame factor levels

I have this code snippet: levels(testing[,c('is_top_rated_listing')]) which returns : NULL however this code returns: levels(testing$is_top_rated_listing) returns "0" "1" Unfortunately I need to use the first approach since the column name…
user3628777
  • 489
  • 2
  • 10
  • 19
-2
votes
1 answer

rename a value in a column according to a condition

I would like to change the name of the entries in the columns of a dataframe when the values of one of the columns are 0. I tried this way, but get an error message. Suppose I would like to change the entries of columns 1,2,3 to "A" when the entries…
user34771
  • 415
  • 1
  • 3
  • 12
-2
votes
2 answers

Give factors numerical value [R]

I want to predict a numerical variable. I have a couple of factors. For all that factors I have a numerical equivalent. Now it would be perfect to assign that numerical equivalent to the factor and use it in the prediction. Is this possible? If this…
nik
  • 1,488
  • 3
  • 14
  • 35
-3
votes
1 answer

how to add legend in R to a ggplot

I have a problem about R, something should be wrong here, I want to add a legend for the two different variables, one is "Insgesamt_ALL" with red colour,and the other one is "weiblich_ALL" with black colour. >…
ZAWD
  • 651
  • 6
  • 28
1 2 3
29
30