r-faq Questions

3

Solved

I have a data frame with a continuous numeric variable, age in months (age_mnths). I want to make a new discrete variable, with age categories based on age intervals. # Some example data rota2 &lt...
Cyanocobalamin asked 26/11, 2012 at 5:22

4

I have recently come across the code |> in R. It is a vertical line character (pipe) followed by a greater than symbol. Here is an example: mtcars |> head() What is the |> code doing?
Diannadianne asked 28/5, 2021 at 19:35

3

Solved

There is a similar question for PHP, but I'm working with R and am unable to translate the solution to my problem. I have this data frame with 10 rows and 50 columns, where some of the rows are ab...
Klehm asked 7/12, 2012 at 12:35

19

Solved

I need to plot a bar chart showing counts and a line chart showing rate all in one chart, I can do both of them separately, but when I put them together, I scale of the first layer (i.e. the geom_b...
Tamberg asked 23/6, 2010 at 5:52

36

Solved

In R, mean() and median() are standard functions which do what you'd expect. mode() tells you the internal storage mode of the object, not the value that occurs the most in its argument. But is the...
Prepotent asked 30/3, 2010 at 17:55

19

Solved

I have a data frame with two columns. First column contains categories such as "First", "Second", "Third", and the second column has numbers that represent the number of times I saw the specific gr...
Nightgown asked 2/11, 2009 at 9:1

12

Solved

I have an R data frame with 6 columns, and I want to create a new dataframe that only has three of the columns. Assuming my data frame is df, and I want to extract columns A, B, and E, this is the...
Demon asked 10/4, 2012 at 2:24

20

Solved

I want to sort a data frame by multiple columns. For example, with the data frame below I would like to sort by column 'z' (descending) then by column 'b' (ascending): dd <- data.frame(b = facto...
Quotha asked 18/8, 2009 at 21:33

9

I want to split a data frame into several smaller ones. This looks like a very trivial question, however I cannot find a solution from web search.
Plummer asked 21/7, 2010 at 18:8

11

Solved

I have code that at one place ends up with a list of data frames which I really want to convert to a single big data frame. I got some pointers from an earlier question which was trying to do som...
Shoshana asked 17/5, 2010 at 17:38

15

Solved

Is it possible to row bind two data frames that don't have the same set of columns? I am hoping to retain the columns that do not match after the bind.
Buonarroti asked 4/8, 2010 at 3:25

7

Solved

The following code is obviously wrong. What's the problem? i <- 0.1 i <- i + 0.05 i ## [1] 0.15 if(i==0.15) cat("i equals 0.15") else cat("i does not equal 0.15") ## i does not equal 0.15
Estabrook asked 29/2, 2012 at 23:46

9

Solved

I have some trouble to convert my data.frame from a wide table to a long table. At the moment it looks like this: Code Country 1950 1951 1952 1953 1954 AFG Afghanistan 20,249 21,352 22,532 23,557 ...
Spinoza asked 2/2, 2010 at 15:36

10

Solved

I have a file: ABCD.csv The length before the .csv is not fixed and vary in any length. How can I extract the portion before the .csv?
Alluvion asked 18/3, 2015 at 4:9

21

Solved

I have a vector of numbers: numbers <- c(4,23,4,23,5,43,54,56,657,67,67,435, 453,435,324,34,456,56,567,65,34,435) How can I have R count the number of times a value x appears in the vector? ...
Strachey asked 17/12, 2009 at 17:21

19

Solved

I have a dataframe and I would like to count the number of rows within each group. I reguarly use the aggregate function to sum data as follows: df2 <- aggregate(x ~ Year + Month, data = df1, s...
Hegumen asked 21/3, 2012 at 16:50

13

Solved

Let's say I have the following data frame: > myvec name order_no 1 Amy 12 2 Jack 14 3 Jack 16 4 Dave 11 5 Amy 12 6 Jack 16 7 Tom 19 8 Larry 22 9 Tom 19 10 Dave 11 11 Jack 17 12 Tom 20 13 Amy 2...
Woald asked 11/10, 2012 at 13:8

22

Solved

In a data.frame (or data.table), I would like to "fill forward" NAs with the closest previous non-NA value. A simple example, using vectors (instead of a data.frame) is the following: &gt...
Fontainebleau asked 12/10, 2011 at 5:27

20

Solved

I have a list and I want to remove a single element from it. How can I do this? I've tried looking up what I think the obvious names for this function would be in the reference manual and I haven'...
Cinnamon asked 16/3, 2009 at 20:59

12

Solved

Say I have a data.frame object: df <- data.frame(name=c('black','black','black','red','red'), type=c('chair','chair','sofa','sofa','plate'), num=c(4,5,12,4,3)) Now I want to count the numbe...
Prot asked 16/9, 2011 at 21:33

7

Solved

I have seen the use of %>% (percent greater than percent) function in some packages like dplyr and rvest. What does it mean? Is it a way to write closure blocks in R?
Pammy asked 25/11, 2014 at 11:37

19

Solved

I tried to install a package, using install.packages("foobarbaz") but received the warning Warning message: package 'foobarbaz' is not available (for R version x.y.z) Why doesn't R think that...
Pinkiepinkish asked 8/9, 2014 at 10:11

9

Solved

Does anyone know how to remove an entire column from a data.frame in R? For example if I am given this data.frame: > head(data) chr genome region 1 chr1 hg19_refGene CDS 2 chr1 hg19_refGene ex...
Djebel asked 8/6, 2011 at 23:2

14

Solved

Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3))) df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1))...
Unite asked 19/8, 2009 at 13:18

10

Solved

R's duplicated returns a vector showing whether each element of a vector or data frame is a duplicate of an element with a smaller subscript. So if rows 3, 4, and 5 of a 5-row data frame are the sa...
Hamel asked 21/10, 2011 at 19:37

© 2022 - 2024 — McMap. All rights reserved.