Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Unexpected change of column name to V1

$
0
0

When running my code I have 2 issues when executing the code after the line "View(df)".

Firstly, I try to delete the first two empty rows, but instead everything gets deleted. EDIT: The selection of the first 2 rows needs to be done with regex. Anything which looks empty should be deleted (An unknown number of spaces or line breaks).

Secondly, the column name is changing unexpectedly to V1. (This is also happening when running the last line of the code without the previous "regex line"). Surprisingly, this issue does not occur when I do not delete the column "a" first.

EDIT: a screen shot after performing the code without the second to last line of code.

column name is changing unexpectedly to V1

Any help is much appreciated!

library(dplyr)

df <- data.frame(a=c(1:8), b=c("", "","tomato", "apple", "orange 1", "peach", "lemon", "orange 2"))
df <- dplyr::select(df, -c(a))
df <- df %>% rename(friut = b)
View(df)

df <- df[grepl("[[:alnum:]]", df$fruit), ]
df <- df[-1, ]

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>