logo
down
shadow

Convert a TIME8. to a Character Without First Converting to Numeric Format


Convert a TIME8. to a Character Without First Converting to Numeric Format

By : حسین نوراحمدی
Date : November 28 2020, 09:01 AM
To fix the issue you can do I am trying to convert a TIME8. value to a character variable in the same original format the TIME8. was in. For example, if the value is 12:30:00, I want a character value that also appears as 12:30:00. , Just use the format TIME8. instead of 8. as shown below,
code :
data _null_;
  val='12:30:00'T;
  num=put(val,time8.);
  put _all_;
run;
1266  data test;
1267    val='12:30:00'T;
1268    num=put(val,time8.);
1269    put _all_;
1270  run;

val=45000 num=12:30:00 _ERROR_=0 _N_=1
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


Share : facebook icon twitter icon
converting multiple columns from character to numeric format in r

converting multiple columns from character to numeric format in r


By : itkhanz
Date : March 29 2020, 07:55 AM
With these it helps What is the most efficient way to convert multiple columns in a data frame from character to numeric format? , You could try
code :
DF <- data.frame("a" = as.character(0:5),
                 "b" = paste(0:5, ".1", sep = ""),
                 "c" = letters[1:6],
                 stringsAsFactors = FALSE)

# Check columns classes
sapply(DF, class)

#           a           b           c 
# "character" "character" "character" 

cols.num <- c("a","b")
DF[cols.num] <- sapply(DF[cols.num],as.numeric)
sapply(DF, class)

#          a           b           c 
#  "numeric"   "numeric" "character"
In R: efficiently convert one format (character vector) to another format (numeric matrix)

In R: efficiently convert one format (character vector) to another format (numeric matrix)


By : Patrick Fokeu
Date : March 29 2020, 07:55 AM
like below fixes the issue Update
To avoid read.csv just use strsplit and the non-exported splitstackshape:::numMat functions:
code :
M <- strsplit(L, "\\s+|:")
cbind(mol = as.numeric(sapply(M, `[`, 1)),
    splitstackshape:::numMat(lapply(M, `[`, -1), fill=0))
L <- c("1  1:1 2:1 3:1 5:1 6:1 8:1",
       "5  1:1 2:1 4:1",
       "9  1:1 2:1 7:1 10:1")
M <- replicate(10000, L)
fun1 <- function() {
  spl <- lapply(strsplit(M,"\\s+|:.? |:.$"),as.numeric)
  vals <- lapply(spl,"[",-1)

  data.frame(
    mol=sapply(spl,"[",1),
    t(sapply(vals, function(x) {
      out <- rep(0,max(unlist(vals)))
      out[x] <- 1
      out} ))
  )
} 

system.time(out_late <- fun1())
#    user  system elapsed 
#   98.36    1.28  100.06
head(out_late)
#   mol X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
# 1   1  1  1  1  0  1  1  0  1  0   0
# 2   5  1  1  0  1  0  0  0  0  0   0
# 3   9  1  1  0  0  0  0  1  0  0   1
# 4   1  1  1  1  0  1  1  0  1  0   0
# 5   5  1  1  0  1  0  0  0  0  0   0
# 6   9  1  1  0  0  0  0  1  0  0   1
library(splitstackshape)
fun2 <- function() {
  M <- strsplit(M, "\\s+|:")
  cbind(mol = as.numeric(sapply(M, `[`, 1)),
        splitstackshape:::numMat(lapply(M, `[`, -1), fill=0))
}

system.time(out_ananda <- fun2())
#    user  system elapsed 
#    0.67    0.00    0.68
head(out_ananda)
#      mol 1 2 3 4 5 6 7 8 9 10
# [1,]   1 1 1 1 0 1 1 0 1 0  0
# [2,]   5 1 1 0 1 0 0 0 0 0  0
# [3,]   9 1 1 0 0 0 0 1 0 0  1
# [4,]   1 1 1 1 0 1 1 0 1 0  0
# [5,]   5 1 1 0 1 0 0 0 0 0  0
# [6,]   9 1 1 0 0 0 0 1 0 0  1
fun3 <- function() {
  t(sapply(strsplit(M, "\\s+"), function(l) {
    mol <- as.numeric(l[1])
    names(mol) <- 'mol'
    val <- numeric(10)
    names(val) <- 1:10
    for (x in strsplit(l[-1], ":"))
      val[x[1]] <- as.numeric(x[2])
    c(mol, val)
  }))
}

system.time(out_matthew <- fun3())
#    user  system elapsed 
#    2.33    0.00    2.34
head(out_matthew)
#      mol 1 2 3 4 5 6 7 8 9 10
# [1,]   1 1 1 1 0 1 1 0 1 0  0
# [2,]   5 1 1 0 1 0 0 0 0 0  0
# [3,]   9 1 1 0 0 0 0 1 0 0  1
# [4,]   1 1 1 1 0 1 1 0 1 0  0
# [5,]   5 1 1 0 1 0 0 0 0 0  0
# [6,]   9 1 1 0 0 0 0 1 0 0  1
Converting factor variables of character format into numeric

Converting factor variables of character format into numeric


By : Salzchneider
Date : March 29 2020, 07:55 AM
hope this fix your issue Judging by your desired output, it doesn't look like you want to convert the factors to the numbers contained in their strings. Instead you want the internal representation of the factors.
Try this:
code :
df[,xxx] <- lapply(df[,factorvars], as.numeric)
#                               x       y  z x_Num y_Num
# 1    10: Already Delinquent 90+  00:Bad  2     1     1
# 2  11: Credit History <6 Months  01:Ind  2     2     2
# 3       12: Current Balance = 0 02:Good  1     3     3
# 4           13: Balance (2-6)=0    <NA>  1     4    NA
# 5                  20: 1+ x 90+  00:Bad  0     5     1
# 6                30: 3+ x 60-89  01:Ind  0     6     2
# 7                 31: 2 x 60-89 02:Good  0     7     3
# 8                 32: 1 x 60-89    <NA>  0     8    NA
# 9                40: 3+ x 30-59  00:Bad  2     9     1
# 10                41: 2 x 30-59  01:Ind  0    10     2
# 11                42: 1 x 30-59 02:Good  0    11     3
# 12 50: Insufficient Performance    <NA>  1    12    NA
# 13                60: 3+ x 1-29  00:Bad  1    13     1
# 14                 61: 2 x 1-29  01:Ind -1    14     2
# 15                 62: 1 x 1-29 02:Good -1    15     3
# 16         70: Never delinquent    <NA> -1    16    NA
is.na(df$y) <- df$y == "NA"
df$y <- droplevels(df$y)
Converting numeric/character column to date format in R

Converting numeric/character column to date format in R


By : WilburMcMullen
Date : March 29 2020, 07:55 AM
To fix this issue Provided that you can start from the non-numeric version of the column (so, maintaining the 0), a possible solution is this:
code :
x <- "0825"
x <- paste(x, "2017", sep ="")
y<- as.Date(as.character(x), "%m%d%Y")
wd <- weekdays(y)
R tidyverse : Dataset structure format and error when converting from character to numeric

R tidyverse : Dataset structure format and error when converting from character to numeric


By : user3119326
Date : March 29 2020, 07:55 AM
wish helps you Every output value in case_when needs to have the same type. You're trying to create a numeric vector, so you can't have TRUE ~ . in case_when: . is character. You can just have the fallback case be NA:
code :
db %>% 
    mutate_at(vars(x1), list(~case_when(
        . == "1 - Nunca" ~ 1,
        . == "2 - Raramente" ~ 2,
        . == "3 - As vezes" ~ 3,
        . == "4 - Quase sempre" ~ 4,
        . == "5 - Sempre" ~ 5,
        TRUE ~ as.numeric(NA)))) 
Related Posts Related Posts :
  • Ignore whitespace in Xtext rule
  • ServiceStack Ormlite: Circular reference between parent and child tables prevents foreign key creation
  • Can't connect to MobileFirst 7.1 server
  • See parameters that are overridden from TeamCity template
  • Can we send collection of messages in QuickBlox using Android SDK
  • SqlFileStream: Returning stream vs byte array in HTTP response
  • tvos: How should we handle low resolution monitor? like 1366x768
  • Aggregation binding only shows last item
  • Gitlab CI artifacts crashes with 403
  • InvalidSessionDescriptionError: Invalid description, no ice-ufrag attribute
  • Missing ionic.project file
  • ispConfig soap client functions of billing module does not exist
  • How to check for dynamic element names in a typeswitch expression?
  • braintree payments integration with zf2( zend framework 2 )
  • Sitecore 8 Admin role: Lock access
  • freemarker looping sequence error
  • How to set multiple commands in one yaml file with Kubernetes?
  • Quartz composer - output specific number
  • make gdb load a shared library from a specific path
  • ADD A COLUMN WITH SR.NO in Sap.m.table irrespective of other columns
  • Can I use SPARQL to query DBPedia for information about Wiki pages such as page length or number of times an article was
  • Jaro Similarity
  • How can I share sessions between Chrome and Paw?
  • how to start developing with OpenText CASE360
  • How to find relation between send and received message in twillio
  • Solve ~(P /\ Q) |- Q -> ~P in Isabelle
  • JetBrains Resharper 9 Ultimate Test Runner error: NUnit.Core.UnsupportedFrameworkException: Skipped loading assembly {My
  • Which RFID and RFID Reader to use?
  • wmi call returning Unexpected COM Error error
  • Training model ignored by stanford CoreNLP
  • z3: Is it possible to adjust the branching heuristics in Z3?
  • SAPUI5_JSON Data binding issue
  • Why does my protractor test have "no specs found" when I include jasmine-reporters in my config file?
  • How to remove "OK" button from Dialog fragment in Android
  • MobileFirst 7.1 connectOnStartup & WL.Client.connect different
  • OrientDB Fetch Plan/Strategies with Tinkerpop
  • Release memory from ID3D11Device::CreateBuffer(...)
  • Samsung SDK: how to install app through apache server and view logs in console?
  • Silex - Redirecting to home page if url not found
  • ImageMagick, Can ImageMagick return single annotation as a bitmap?
  • Block access to some LAN ip`s using PFsense
  • noVNC Multiple Localhost Servers
  • What casts are allowed with `as`?
  • Google Drive API append file?
  • nix-env -qa not showing latest packages
  • In TI-BASIC, how do I add a variable in the middle of a String?
  • NetBeans - Display .gitignore Files in Projects/Files
  • Why is my command prompt freezing on Windows 10?
  • pass python arguments with argument name
  • Storing a time stamp(Calendar object) with objectify
  • XSLT to copy element without default/old namespace
  • Spark: join key-tuple pairs into key-list value
  • RethinkDB: Get last N from an object
  • How to direct my index to MediaWiki index.php
  • Removing ExecControl to upgrade to Ratpack v1.1.1?
  • When registering a table using the %pyspark interpreter in Zeppelin, I can't access the table in %sql
  • Phaser Sprite for joint between two bodies
  • The system detected a protection exception
  • OpenCL cannot find GPU device: NVIDIA GPU (Quadro K4000) + Visual Studio 2015
  • Rendr add custom header to fetch request (such as basic auth)
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co