So I have a data frame that includes a column like this: image
And I would like to remove the operator as well as the numbers to the right of it, ie so the first entry would just say 51.81 rather than 51.81 - 11.19. How would I go about this? I feel like using a for loop might work but I'm unsure of the syntax required.
Thanks
我们可以使用sub
来匹配零个或多个空格 ( \\\\s*
) 后跟-
或+
等字符,并替换为空白 ( ""
)
df1$xG <- as.numeric(sub("\\s*[-+]+.*", "", df1$xG))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.