I want to access all the rows in a column except the first three rows.

I tried df[3:,]

But this gives an error but df[3:100,] works. but in some file, the rows exceed the 100 row limit. How to make the lower limit dynamic?

I want to access all the rows in a column except the first three rows.

I tried df[3:,]

But this gives an error but df[3:100,] works. but in some file, the rows exceed the 100 row limit. How to make the lower limit dynamic?

0 Likes

You can always use `df[3:nrow(df),]`

.

Keep in mind that R uses 1-based indices, so if you want to drop first three rows, you'll use `df[4:nrow(df),]`

2 Likes

Another way is to drop the 1st three rows will be to use `df[-(1:3),]`

, which is more intuitive to me.

3 Likes

@mishabalyasin @Yarnabrina this is the file now I need to access all the values from the 3rd row.

and then applying the condition

pos <-df[which((df[-(1:2),3]<=input$p_val)&(df[-(1:2),2]>0)), ]

neg <-df[which((df[-(1:2),3]<=input$p_val)&(df[-(1:2),2]<0)), ]

currently, it gives me a huge error.

Warning in Ops.factor(df[-(1:2), 3], input$p_val) :

'<=' not meaningful for factors

Warning in Ops.factor(df[-(1:2), 2], 0) :

'>' not meaningful for factors

Warning in Ops.factor(df[-(1:2), 3], input$p_val) :

'<=' not meaningful for factors

Warning in Ops.factor(df[-(1:2), 2], 0) :

'<' not meaningful for factors

0 Likes

Hi @SaeedRehman, I think you might be better off skipping only one row, and doing it when you read the file from disk. This will let you use the second row as the column names, and also avoid the warning you're seeing about using factors as numbers.

Your data is getting read in as strings, not numbers, because there are non-numeric strings like `"Fold change"`

and `"p Value"`

in the cells. Then those strings are being auto-converted to factors. So your selection by `<=`

or `>`

aren't working either.

Try something like this:

```
install.packages("readxl")
library(readxl)
df <- read_excel("your-filename-here.xlsx", skip=1)
pos <- df[df$p.Value <= input$p_val & df$Fold.change > 0, ]
neg <- df[df$p.Value <= input$p_val & df$Fold.change < 0, ]
```

Those last two lines could be changed to something like this for readability if you desire:

```
pos <- subset(df, p.Value <= input$p_val & Fold.change > 0)
neg <- subset(df, p.Value <= input$p_val & Fold.change < 0)
```

1 Like