Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping specific rows and columns in R

I skipped second row of the data using this command:

Df=(read.csv(“IMDB_data.csv”, header=T, sep=",")[-2,])

What is the explanation behind this? Can it be used for skipping more than 1 specific row? Can it used for skipping columns? Please help.

like image 424
user9716225 Avatar asked Apr 29 '18 03:04

user9716225


People also ask

How do I grab certain rows in R?

By using bracket notation on R DataFrame (data.name) we can select rows by column value, by index, by name, by condition e.t.c. You can also use the R base function subset() to get the same results. Besides these, R also provides another function dplyr::filter() to get the rows from the DataFrame.

How do I select only certain columns in R?

To pick out single or multiple columns use the select() function. The select() function expects a dataframe as it's first input ('argument', in R language), followed by the names of the columns you want to extract with a comma between each name.

How do I switch columns and rows in R?

Rotating or transposing R objects frame so that the rows become the columns and the columns become the rows. That is, you transpose the rows and columns. You simply use the t() command. The result of the t() command is always a matrix object.


1 Answers

You can "skip" as many rows using negative values, i.e.

Df=(read.csv(“IMDB_data.csv”, header=T, sep=",")[-c(2,3,5:9),])

Similar for columns:

Df=(read.csv(“IMDB_data.csv”, header=T, sep=",")[, -c(2,4)])

To skip rows and columns

Df=(read.csv(“IMDB_data.csv”, header=T, sep=",")[-c(2,3,5:9), -c(2,4)])
like image 163
Katia Avatar answered Oct 18 '22 08:10

Katia