multiply_csv: Multiply comma-separated numbers in a character vector by a...

View source: R/utils_rmats.R

multiply_csvR Documentation

Multiply comma-separated numbers in a character vector by a number, handling NAs

Description

This function takes a character vector containing comma-separated numbers and multiplies each number by 100. It handles missing values (NAs) by returning NA for elements that cannot be converted to numeric.

Usage

multiply_csv(x, k = 100)

Arguments

x

A character vector containing comma-separated numbers.

k

The number to multiply by. Default 100.

Value

A character vector with the same number of elements as x, where each element is the product of the original number and k, or NA if the original element could not be converted to numeric.

Examples

x <- c("0.1,0.2,NA,0.3", "0.4,0.5,NA,0.66")
multiply_csv(x)
# "10,20,NA,30" "40,50,NA,66"
y <- c("0.2,!!,0.9,NA", "*,NA,0.015")
multiply_csv(y)
# "20,NA,90,NA"  "NA,NA,1.5,NA"

Ni-Ar/niar documentation built on Feb. 3, 2025, 9:25 a.m.