Tag: dataframe

52 votes
18 answers
1.5K views
Convert data.frame columns from factors to characters

I have a data frame. Let's call him bob: > head(bob) phenotype

avatar
Karolyn
0 1 0 9
asked 07 September, 2021
62 votes
11 answers
3.1K views
Sample random rows in dataframe

I am struggling to find the appropriate function that would return a specified number of rows picked up random

avatar
Luis
0 1 0 9
asked 07 September, 2021
65 votes
9 answers
1.6K views
Combine a list of data frames into one data frame by row

I have code that at one place ends up with a list of data frames which I really want to convert to a single bi

avatar
Emilia
0 1 0 9
asked 07 September, 2021
53 votes
10 answers
1.8K views
Extracting specific columns from a data frame

I have an R data frame with 6 columns, and I want to create a new dataframe that only has three of the columns

avatar
Fabian
0 1 0 9
asked 07 September, 2021
57 votes
15 answers
1.5K views
How to sum a variable by group

I have a data frame with two columns. First column contains categories such as "First", "Second", "Third", and

avatar
Emilia
0 1 0 9
asked 07 September, 2021
52 votes
16 answers
3K views
Changing column names of a data frame

I have a data frame called "newprice" (see below) and I want to change the column names in my program in R. &

avatar
Luis
0 1 0 9
asked 07 September, 2021
58 votes
11 answers
2.7K views
Quickly reading very large tables as dataframes

I have very large tables (30 million rows) that I would like to load as a dataframes in R. read.table() has a

avatar
Thurman
0 1 0 9
asked 07 September, 2021
58 votes
17 answers
2.1K views
Create an empty data.frame

I'm trying to initialize a data.frame without any rows. Basically, I want to specify the data types for e

avatar
Keila
0 1 0 9
asked 07 September, 2021
46 votes
15 answers
709 views
Drop unused factor levels in a subsetted data frame

I have a data frame containing a factor. When I create a subset of this dataframe using subset or another inde

avatar
Omar
0 1 0 9
asked 07 September, 2021
67 votes
24 answers
2.5K views
Convert a list to a data frame

I have a nested list of data. Its length is 132 and each item is a list of length 20. Is there a quick way to

avatar
Shanita
0 1 0 9
asked 07 September, 2021
49 votes
12 answers
2.6K views
The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframe

R provides two different methods for accessing the elements of a list or data.frame: [] and [[]]. What is the

avatar
Xavier
0 1 0 9
asked 07 September, 2021
61 votes
25 answers
2.7K views
How do I replace NA values with zeros in an R dataframe?

I have a data frame and some columns have NA values. How do I replace these NA values with zeroes?

avatar
Alba
0 1 0 9
asked 07 September, 2021
60 votes
17 answers
1.7K views
Remove rows with all or some NAs (missing values) in data.frame

I'd like to remove the lines in this data frame that: a) contain NAs across all columns. Below is my exa

avatar
Jefferey
0 1 0 9
asked 07 September, 2021
58 votes
21 answers
1.6K views
Drop data frame columns by name

I have a number of columns that I would like to remove from a data frame. I know that we can delete them indiv

avatar
Hilario
0 1 0 9
asked 07 September, 2021
54 votes
13 answers
2.9K views
How to join (merge) data frames (inner, outer, left, right)

Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3)))

avatar
Dorinda
0 1 0 9
asked 07 September, 2021
64 votes
19 answers
698 views
How to sort a dataframe by multiple column(s)

I want to sort a data.frame by multiple columns. For example, with the data.frame below I would like to sort b

avatar
Venice
0 1 0 9
asked 07 September, 2021
53 votes
10 answers
641 views
How to take column-slices of dataframe in pandas

I load some machine learning data from a CSV file. The first 2 columns are observations and the remaining colu

avatar
Basil
0 1 0 9
asked 07 September, 2021
62 votes
23 answers
2.8K views
What does axis in pandas mean?

Here is my code to generate a dataframe: import pandas as pd import numpy as np dff = pd.DataFrame(np.random

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
53 votes
10 answers
2.5K views
Pandas conditional creation of a series/dataframe column

I have a dataframe along the lines of the below: Type Set 1 A Z 2 B Z

avatar
Janella
0 1 0 9
asked 07 September, 2021
60 votes
10 answers
1.8K views
Pandas read_csv low_memory and dtype options

When calling df = pd.read_csv('somefile.csv') I get: /Users/josh/anaconda/envs/py27/lib/pytho

avatar
Fabian
0 1 0 9
asked 07 September, 2021