Questions tagged [r-table]

R has a table function which creates a matrix-like object.

R has a table function which creates a matrix-like object, but using [table] as a tag alone is deprecated because it is so general a term as to be meaningless.

35 questions
13
votes
5 answers

Make a table showing the 10 largest values of a variable in R?

I want to make a simple table that showcases the largest 10 values for a given variable in my dataset, as well as 4 other variables for each observation, so basically a small subset of my data. It would look something like this: Score District Age…
nikUoM
  • 639
  • 1
  • 8
  • 18
9
votes
4 answers

How to access values in a frequency table

I have a frequency table, counting the frequency of elements in a vector a = table(c(0,1,1,1,0,2,2,4,1,2,3,2,1,2,3,1,1,1,2,3,4,1,1,0)) a # 0 1 2 3 4 # 3 10 6 3 2 I know I can access the name by names(a). But when I tried to access the…
Minh Nguyen
  • 111
  • 1
  • 4
6
votes
1 answer

Why does the table function find a variable that was deleted

Why does the table function find a variable that was deleted? Dog <- c("Rover", "Spot") Cat <- c("Scratch", "Fluffy") Pets <- data.frame(Dog, Cat) #create a data frame with two variables names(Pets) # [1] "Dog" "Cat" #rename Dog to a longer…
user2502904
  • 179
  • 4
  • 13
3
votes
1 answer

Finding the original vectors from an interaction table

A = c(1,2,3,2,1,2,2,2,1,2,3,2,1) B = c(2,3,2,3,2,2,1,1,2,1,2,2,3) mytable = table(A,B) What is the best solution to find back the two vectors from mytable? Of course, it will not be the exact same vectors but the order of A compared to B has to be…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
2
votes
2 answers

apply function removing 0 counts from table() output of ordered factors

Assume the following data.frame with columns of ordered factors: dat0 <- data.frame(X1 = 1:5, X2 = 1:5, X3 = c(1,1:4), X4 = c(2,2:5)) dat <- data.frame(lapply(dat0, factor, ordered=TRUE, levels=1:5, labels=letters[1:5])) I want to create a nice…
theforestecologist
  • 4,667
  • 5
  • 54
  • 91
2
votes
1 answer

How to convert outcome of table function to a dataframe

df = data.frame(table(train$department , train$outcome)) Here department and outcome both are factors so it gives me a dataframe which looks like in the given image is_outcome is binary and df looks like this containing only 2 variables(fields)…
Sagar Arora
  • 21
  • 1
  • 4
2
votes
1 answer

R error - Table of extent 0

I'm a complete newbie to R so I'm currently trying to work my way through Youtube videos and books as I need to use R for a paper. I'm working in R Studio. I'm currently trying to get the frequency of one one of the features in my data. The value…
Jalui
  • 37
  • 1
  • 1
  • 5
2
votes
1 answer

Combining a single column matrix with a table in R in the manner of 'sweep'

I have a single column matrix (the result of an rbind operation) of initial starting values named 'starts' for several timeseries which begin at different months and appears as follows: starts <- matrix(rep(100,5),ncol=1) rownames(starts) <-…
RichS
  • 659
  • 12
  • 19
2
votes
1 answer

After using table(A,B) in R, how can I order the columns and rows according to a particular ordering?

I am working in R and have tabulated two columns of a dataframe by using table(A,B) The final table, call it TAB has 4 x 4 columns. I want to order them based off some other ordering I came up with. The order from col1 - col4 I want is in vector…
wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
1
vote
1 answer

How to make an APA ready correlation table in R

I want to turn an intervariable correlations table in R to a table formatted according to APA styles. The table should have the following characteristics Have only lower or upper diagonal of the matrix Usually display correlation coefficients only…
Ehsan88
  • 3,569
  • 5
  • 29
  • 52
1
vote
2 answers

R: Transpose the a results table and add column headers

Setting the scene: So I have a directory with 50 .csv files in it. All files have unique names e.g. 1.csv 2.csv ... The contents of each may vary in the number of rows but always have 4 columns The column headers are: Date Result 1 Result 2 ID I…
Mchapple
  • 43
  • 2
  • 10
1
vote
0 answers

How to use tabulated data in a density function in R?

My real data has 91 continuous categorical values with counts ranging from 1,230 to 300,239. So that means I have a table with 91 categories and 91 corresponding y values counting how many points fall within that categories. How would I go about…
Meli
  • 345
  • 5
  • 15
1
vote
2 answers

droplevels() messes with table() so as to produce wrong counts

I have a large data frame that I'm trying to subset and then table. In order to get rid of unused levels inherited from the superset (the original data frame), I use droplevels(), but this somehow messes up the counts in table(): #without…
SiKiHe
  • 439
  • 6
  • 16
1
vote
2 answers

How to create a table with two-factorial data

is there a possibility to show data that is two-factorial in a table using R? Please consider my example with replicates. So one has two or more values in every cell. I tried using ftable() and table() but am not getting anywhere :( Thank you so…
feinmann
  • 1,060
  • 1
  • 14
  • 20
0
votes
2 answers

adding the frequency column in R without using dyplr

I have a "wide" dataset where for each observation I measure a value from a bunch of categorical variables. It is presented just like this: V1 V2 V3 a z f a z f b y g b y g a y g b y f this means that V1 has two categories "a"…
Bibi
  • 87
  • 9
1
2 3